Hum*_*ger 4 c datetime boost unix-timestamp
给定time_tas 1291121400,如何将当天的日期格式化为20101130?
使用gmtime(3)或localtime(3)将其转换为struct tm
(或更好,可重入的版本gmtime_r或localtime_r),然后用strftime(3)它将其转换为字符串.例如,如果您想要UTC格式的输出:
struct tm tm;
char buf[9];
gmtime_r(&my_time_t, &tm);
strftime(buf, sizeof(buf), "%Y%m%d", tm);
printf("The date is: %s\n", buf);
Run Code Online (Sandbox Code Playgroud)