#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教程网
时间: 2024-10-11 10:56:51