首页 > 代码库 > linux c 获取系统时间
linux c 获取系统时间
#include <time.h>main(){time_t timep;time (&timep);printf(“%s”,asctime(gmtime(&timep)));}
#include<time.h>main(){time_t timep;time (&timep);printf(“%s”,ctime(&timep));}
#include<sys/time.h>#include<unistd.h>main(){struct timeval tv;struct timezone tz;gettimeofday (&tv , &tz);printf(“tv_sec; %d\n”, tv,.tv_sec) ;printf(“tv_usec; %d\n”,tv.tv_usec);printf(“tz_minuteswest; %d\n”, tz.tz_minuteswest);printf(“tz_dsttime, %d\n”,tz.tz_dsttime);}
#include<sys/time.h>#include<unistd.h>main(){struct timeval tv;struct timezone tz;gettimeofday (&tv , &tz);printf(“tv_sec; %d\n”, tv,.tv_sec) ;printf(“tv_usec; %d\n”,tv.tv_usec);printf(“tz_minuteswest; %d\n”, tz.tz_minuteswest);printf(“tz_dsttime, %d\n”,tz.tz_dsttime);}
#include<time.h>main(){char *wday[]={“Sun”,”Mon”,”Tue”,”Wed”,”Thu”,”Fri”,”Sat”};time_t timep;struct tm *p;time(&timep);p=localtime(&timep); /*取得当地时间*/printf (“%d%d%d ”, (1900+p->tm_year),( l+p->tm_mon), p->tm_mday);printf(“%s%d:%d:%d\n”, wday[p->tm_wday],p->tm_hour, p->tm_min, p->tm_sec);}
#include<time.h>main(){time_t timep;strcut tm *p;time(&timep);printf(“time() : %d \n”,timep);p=localtime(&timep);timep = mktime(p);printf(“time()->localtime()->mktime():%d\n”,timep);}
#include<time.h>main(){int seconds= time((time_t*)NULL);printf(“%d\n”,seconds);}
- 本文来自:Linux教程网
linux c 获取系统时间
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。