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教程网
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。