#include <stdio.h> #include <sys/time.h> #include <time.h> int gettimeofday(struct timeval *tv, struct timezone *tz); int main(int argc,char * argv[]) { struct timeval tv;
struct tm *gmt, *area;
//打印文件名和此段程序行數,並顯示系統時間和微秒數; printf("%s:%d linetime %u:%u\n",__FILE__,__LINE__,tv.tv_sec,tv.tv_usec);
area = localtime(&(tv.tv_sec));以本地時區顯示時間
printf("Local time is: %s", asctime(area));
gmt = gmtime(&(tv.tv_sec));以GMT時區顯示時間
printf("GMT is: %s", asctime(gmt));
sleep(2); } return 0; }