#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;
while(1)
{
gettimeofday(&tv,0);
//打印文件名和此段程序行数,并显示系统时间和微秒数;
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; }