#include <stdio.h>
#include <time.h>
int main()
{
struct tm *tm;
while(1) {
time_t t = time(NULL);
tm = localtime(&t);
system("clear");
printf("%d-%d-%d\t%d:%d:%d\n",1900+tm->tm_year,tm->tm_mon,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
sleep(1);
}
return 0;
}
看下这个例子,应该就明白了其中tm的结构体是
struct tm {
int tm_sec;
/* seconds */
int tm_min;
/* minutes */
int tm_hour;
/* hours */
int tm_mday;
/* day of the month */
int tm_mon;
/* month */
int tm_year;
/* year */
int tm_wday;
/* day of the week */
int tm_yday;
/* day in the year */
int tm_isdst;
/* daylight saving time */
};
都是在time.h里定义好了的