1. 程式人生 > >將時間戳轉換成當前年月日

將時間戳轉換成當前年月日

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;