The introduction of C + + common time function

Source: Internet
Author: User

Turn from: http://blog.csdn.net/ljx0305/article/details/8904285


Before we introduce, we'll introduce two concepts

Coordinated Universal Time (UTC): When reconciling the world, it is also known as world standard Times, known as Greenwich Mean Time (Greenwich Mean time,gmt). In China, for example, the time difference from UTC is +8, which is utc+8. The United States is UTC-5.

Calendar Time : The time that is represented by the number of seconds elapsed from a standard point in time to this time. This standard point in time is different for various compilers, but for a compilation system, this standard time point is invariant, the time corresponding to the calendar time in the compilation system is measured by the standard point of time, so you can say that calendar time is "relative time", but no matter which time zone you are in, At the same time, the calendar time is the same for the same standard point. (In short, it can be understood that CT time is UTC time minus 1900-01-01 00:00:00).

Data structures related to date and time

CPP code typedef LONG time_t;         /* Time value */ [CPP] view plain copy typedef long time_t; /* Time Value * *

You may be wondering: Since time_t is actually a long integer, one day in the future, from one point of time (typically January 1, 1970 0:0 0 seconds) to the number of seconds (that is, the calendar time) exceeds the range of numbers that can be represented by long shaping. For a value of the time_t data type, the time it represents cannot be as late as January 18, 2038 19:14 07 seconds. To be able to represent a longer time, some compiler vendors have introduced 64-bit or even longer cosmetic numbers to hold the calendar time. For example, Microsoft uses the __time64_t data type in Visual C + + to hold the calendar time, and through the _time64 () function to obtain the calendar time (instead of using the 32-bit word () function), This allows you to save the time before January 1, 3001 0:0 0 seconds (excluding that point) from the data type.

CPP code structTM{intTm_sec; /* seconds-Take the value range is [0,59] * *intTm_min; /* Divide-take value range is [0,59] * *intTm_hour; /* Time-value range is [0,23] * *intTm_mday; * * One months date-value range is [1,31]/I NT Tm_mon; /* Month (starting from January, 0 represents January)-the value range is [0,11] * *intTm_year; /* Year with the value equal to the actual year minus 1900 * *intTm_wday; /* Week – The value range is [0,6], of which 0 represents Sunday, 1 for Monday, and so on * *intTm_yday; /* The number of days from January 1 of each year – the value interval is [0,365], of which 0 represents January 1, 1 is January 2, and so on.intTM_ISDST; /* Daylight Saving time identifier, TM_ISDST is positive when implementing daylight savings.                       When daylight saving time is not implemented, the TM_ISDST is 0 and TM_ISDST () is negative when the situation is not known. Daylight saving time can be found on the internet, in China, no longer use daylight saving Time/};[CPP]  View plain copy struct tm    {        int tm_sec;  /*  sec  -  Value range is [0,59] */        int tm_min;  /*   -  value range for [0,59] */        int tm_hour;  /*   -  interval for [0,23] */        int tm_mday;  /*  one-month date  -  value range is [1,31] */ i       nt tm_mon ; /*  month (starting from January, 0 represents January)-  range is [0,11] */        int tm_ year; /*  year with a value equal to the actual year minus 1900 */         int tm_wday;  /*  Week – The value range is [0,6], where 0 represents Sunday, 1 represents Monday, and so on  */        int tm_ yday; /*  from January 1 of each year, the number of days  –  values range is [0,365], of which 0 represent January 1, 1 for January 2, and so on  */

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.