struct tm结构体
image.png
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
int main() {
time_t cur_time = time(NULL);
struct tm* timer = localtime(&cur_time);
int year = timer->tm_year + 1900;
int month = timer->tm_mon+1;
int day = timer->tm_mday;
int hour = timer->tm_hour;
int min = timer->tm_min;
int second = timer->tm_sec;
int week = timer->tm_wday; // 0-6
const char* weeks[] = {"日","一","二","三","四","五","六"};
printf("%d年%d月%d日 %d:%d:%d 星期%s \n", year, month, day, hour, min, second, weeks[week]);
return 0;
}
image.png
网友评论