#include <stdio.h>
#include <time.h>
int main(void)
{
char *wday[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
time_t t;
struct tm *p;
int year = 0, mon = 0, mday = 0;
int hour = 0, min = 0, sec = 0;
char *week = NULL;
time(&t);
p = gmtime(&t);
year = 1900 + p->tm_year;
mon = 1 + p->tm_mon;
mday = p->tm_mday;
week = wday[p->tm_wday];
hour = 8 + p->tm_hour; //获取当地时间,与UTC时间相差8小时
min = p->tm_min;
sec = p->tm_sec;
printf("%d-%d-%d %s", year, mon, mday, week);
printf(" %.2d:%.2d:%.2d\n", hour, min, sec);
return 0;
}
网友评论