加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux下获取系统时间 和 时间偏移

发布时间:2020-12-14 01:31:31 所属栏目:Linux 来源:网络整理
导读:获取linux时间? 并计算时间偏移 void getSystemTimer(void){#if 0 char *wdate[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"} ; time_t timep; struct tm *p; time(timep); p=gmtime(timep); printf("n************************* %d:%d:%d **************

获取linux时间? 并计算时间偏移

void getSystemTimer(void){#if 0 char *wdate[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"} ; time_t timep; struct tm *p; time(&timep); p=gmtime(&timep); printf("n************************* %d:%d:%d **************************n",p->tm_hour,p->tm_min,p->tm_sec);#endif static char flag=0; static long lastsecond = 0 ; //old long timeoffset = 0 ; //now struct timeval tv; struct timezone tz; gettimeofday(&tv,&tz); if(flag==0){ lastsecond = tv.tv_sec ; flag = 1 ; } timeoffset = tv.tv_sec - lastsecond ; //get offsettime printf("n************************* %d:%d:%d **************************n",(timeoffset/60)/60,(timeoffset/60)%60,timeoffset%60) ;}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读