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 );