Time functions used and summarized by C library functions, summary functions of c library functions
1. localtime (obtain the current local time and date)
[Header file] # include <time. h>
[Function prototype] struct tm * localtime (const time_t * timep );
[Function description] localtime () converts the information in the time_t structure referred to by the timep parameter to the time and date representation method used in the real world, and then returns the result from the structure tm. For the definition of the structure tm, see gmtime (). The time date returned by this function has been converted to the local time zone.
[Return value] The returned structure tm indicates the current local time.
[Note] the return value of the function is a pointer, and the actual memory is the static memory applied internally by localtime. Therefore, if the return value after calling localtime is not used in time, it is likely to be overwritten by localtime calls of other threads. Other time functions, such as asctime, asctime_r; ctime, ctime_r; gmtime and gmtime_r, are similar. Therefore, the _ r version of the time function is thread-safe.
2. mktime (the number of seconds after the time structure data is converted)
[Header file] # include <time. h>
[Function prototype] time_t mktime (strcut tm * timeptr );
[Function description] mktime () is used to convert the tm structure data referred to by the timeptr parameter to the number of seconds that have elapsed since 00:00:00, January 1, January 1, 1970 AD.
Return Value: the number of seconds that have elapsed.
3. difftime (calculate the time difference between two systems)
[Header file] # include <time. h>
[Function prototype] double difftime (time_t timer1, time_t timer0 );
[Function description] calculates the time difference between two moments.
Return Value: returns the interval between two time_t variables.