看linux程序设计的第四章-时间和日期,看到这个程序,感觉有点用,发到博客吧,不过有点小问题,运行时tm_hour的结果不正确,有待检查
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
struct tm *tm_ptr;
time_t the_time;
(void)time(&the_time);
tm_ptr = gmtime(&the_time);
printf("date :%02d/%02d/%02d", tm_ptr->tm_year+1900, tm_ptr->tm_mon+1, tm_ptr->tm_mday);
printf(" %02d:%02d:%02d\n", tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec);
return 0;
}
date :2012/11/03 11:26:39