Unix timestamp time_t relationship to UTC time zone

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.