将时间戳转换成当前年月日

来源:互联网 发布:mysql创建用户sql语句 编辑:程序博客网 时间:2024/05/21 06:31

time_t t;
struct tm *now;
t = 1452602092 + 28800; // 在linux系统上会差8个小时 要加上28800 因为时区的不同
now = gmtime(&t);
char s[100];
strftime(s, sizeof(s), “%Y-%m-%d %H:%M:%S”, p);
printf(“%d: %s\n”, (int)t, s);

int year = now->tm_year + 1900;
int month = now->tm_mon + 1;
int day = now->tm_mday;
int hour = now->tm_hour;
int minute = now->tm_min;
int second = now->tm_sec;

1 0