Normally I write Unix timestamps like this in C.
#include <stdio.h>#include<time.h>voidPRINTFDATETIMESTR (structTM *STM) { Charweekday[][4]={"days","a","two","three","Four","Five","Six"}; printf ("timestr=%04d-%02d-%02d%02d:%02d:%02d Week%s\n", stm->tm_year+1900, stm->tm_mon+1,stm->tm_mday,stm->tm_hour,stm->tm_min,stm->tm_sec,weekday[stm->tm_wday]);}intMain () {time_t Unix_timestamp=1429641418; Unix_timestamp=Time (NULL); structTM *tmdate=localtime (&Unix_timestamp); printf ("Unix_timestamp Now the timestamp is =%d\n", Unix_timestamp); printf ("Local Time is:asctime=%s", Asctime (tmdate)); printf ("Greenwich GMT Time is:gmtime=%s", Asctime (Gmtime (&( Unix_timestamp))); Printfdatetimestr (tmdate); printf ("========================================\n"); printf ("input your Unix_timestamp:"); scanf ("%d",&Unix_timestamp); structTM *stm=localtime (&Unix_timestamp); printf ("your unix_timestamp time stamp is =%d\n.", Unix_timestamp); printf ("your Local time is:asctime=%s", Asctime (STM)); printf ("Your Greenwich GMT time is:gmtime=%s", Asctime (Gmtime (&( Unix_timestamp))); PRINTFDATETIMESTR (STM); CharC; scanf ("%c",&c); return 0;}
Operation Result:
Unix_timestamp now the timestamp is =1429787951
Local time Is:asctime=thu APR 23 19:19:11 2015
Greenwich GMT TIME Is:gmtime=thu APR 23 11:19:11 2015
timestr=2015-04-23 11:19:11 Thursday Dst[0]
========================================
Input your unix_timestamp:0
Your unix_timestamp time stamp is =0.
Your Local time Is:asctime=thu Jan 01 08:00:00 1970
Your Greenwich GMT time Is:gmtime=thu Jan 01 00:00:00 1970
timestr=1970-01-01 00:00:00 Thursday Dst[0]
time_t =0 is actually 1970-01-01 00:00:00 to UTC 0 time zone seconds, not our Beijing time utc+8; so gmtime is 8 hours smaller than localtime.
In most Unix systems, the UNIX timestamp is stored as 32 bits, which can cause 2038 problems or Y2038.
Replace the morning and evening with 64-bit.
Unix timestamp time_t relationship to UTC time zone