#include <stdio.h>
#include <time.h>
struct tm *get_time(void)
{
time_t t;
time(&t);
t += 8*60*60; // 加时区
struct tm *tm = localtime(&t);
tm->tm_year += 1900;
tm->tm_mon += 1;
return tm;
}
int main(void)
{
struct tm *tm = get_time();
printf("%4d年%02d月%02d日 %02d:%02d:%02d\n",
tm->tm_year,tm->tm_mon,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
return 0;
}
运行结果:
C 库函数 – localtime() | 菜鸟教程 (runoob.com)
C语言应用(1)——Unix时间戳和北京时间的相互转换 (eepw.com.cn)
标签:02d,struct,year,60,获取,tm,时间,time From: https://www.cnblogs.com/kernelx/p/17236069.html