Time functions used and summarized by C library functions, summary functions of c library functions

Source: Internet
Author: User

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.

 

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.