UNIX time related functions

Source: Internet
Author: User

UNIX time can be roughly divided into real-time and time in the struct.

1 \ calculate the number of seconds from 1900 to 1970 rfc1305-Network Time Protocol. In the network protocol, the timestamp format is a four-eight-bit group. The value is the number of seconds since January 1, 1900. UNIX does not provide functions to obtain the number of seconds since January 1, 1900, but it provides the number of seconds since January 1, 1970 (UTC time. Because the number of days between 1900 and 1970 is a fixed value. So we can get the number of seconds since January 1, 1970. // 366 days of a leap year, 365 days of a year, 18 leap years from 1900 to 1970, static const int seconds = (1970-1900) * 365 + 18) * 24*60*60; In the Time Precision poxis standard, the time precision that can be obtained is microsecond (UM ). This is obtained using gettimeofday. It must be noted that the system seconds obtained by the time () function are not necessarily a precise value. It may be one second behind the value obtained by gettimeofday. Because time () is a function rather than a system call. It takes only one data structure saved in the system. Therefore. In high precision scenarios, the number of seconds obtained by time () must be compared with the number of seconds obtained by gettimeofday. If not, add one second to the time obtained.
Gettimeofday (&
Time_t trecv, tsend;
// Obtain the current localtimetime (& tsend );
// The number of seconds for completing the difference tsend + = (now. TV _sec & 1) ^ (tsend & 1 ));
Some systems provide functions for obtaining nanoseconds. In addition, the ODBC timestamp_struct data type also provides the precision to the nanoseconds.

 


 

 

 

Timeval now;
Now, null );


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.