Progress of large operating system experiments (5) ----- detailed introduction of time_t Data Types in C/C ++

Source: Internet
Author: User
Tags integer numbers microsoft c

Include File: # ifndef _ TIME_T # define _ TIME_T/* avoid repeatedly defining time_t */typedef long time_t; /* The Time Value time_t is the alias of a long integer */# endif since time_t is actually a long integer, to a certain day in the future, from a time point (usually January 1, 1970 00:00:00) by that time, the number of seconds (that is, the calendar time) exceeds the range of the number that can be expressed by a long integer. What should I do? For a value of the time_t data type, the time it represents cannot be later than January 18, 2038. To represent a longer period of time, some compiler vendors have introduced 64-bit or even longer integer numbers to save the calendar time. For example, Microsoft uses the _ time64_t data type in Visual C ++ to save the calendar time, and uses _ time64 () function to obtain the calendar time (instead of using the 32-bit time () function), you can use this data type to save the time before 00:00:00, January 1, January 1, 3001 (excluding this time point. In time. in the h header file, we can also see some functions that are of the time_t parameter type or return value type: double difftime (time_t time1, time_t time0 ); time_t mktime (struct tm * timeptr); time_t time (time_t * timer); char * asctime (const struct tm * timeptr); char * ctime (const time_t * timer, time. h also provides two different functions to convert the calendar time (an integer expressed in time_t) to the time format that we usually see separately displaying year, month, day, hour, minute, and second. tm: www.2cto. comstruct tm * gmtime (const time_t * timer); struct tm * localtime (const time_t * timer ); Www.2cto.com by referring to MSDN, we can know that the value of the time point in Microsoft C/C ++ 7.0 (the value of the time_t object) is the number of seconds passed from 00:00:00 on January 1, December 31, 1899 to this time point, microsoft C/C ++ of other versions and Visual C ++ of all different versions calculate the number of seconds that have elapsed since 00:00:00, January 1, January 1, 1970 to this time point. Time_t occupies 8 digits: there is a picture with truth

Related Article

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.