Time_t data type in C Language

Source: Internet
Author: User
Tags integer numbers microsoft c

From: http://maxim.eefocus.com/xuefu2009/blog/10-03/187348_f456a.html

Include files : # Ifndef _ time_t # DEFINE _ time_t /* Avoid repeated Definitions Time_t */Typedef long Time_t ;/* Time Value Time_t is the alias of a long integer */# endif although 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 compilers introduce 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 January 1, 3001 00:00:00 (excluding this time point) the time before. In the time. h header file, we can also see some functions, all of which are functions 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 ); In addition, 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: struct TM * gmtime (const time_t * timer ); Struct TM * localtime (const time_t * timer); by reading msdn, we can know the value of the time point in Microsoft C/C ++ 7.0 (value of the time_t object) the number of seconds that have elapsed since 00:00:00, 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.

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.