The time function of C library function

Source: Internet
Author: User

LocalTime (get local current time and date)

"Header file" #include <time.h>

"Function prototype" struct TM *localtime (const time_t * TIMEP);

The function Description localtime () Converts the information in the time_t structure referred to by the parameter TIMEP to the time date representation used by the real world, and then returns the result from the Fabric TM. Please refer to Gmtime () for the definition of structure TM. The time date returned by this function has been converted to the local time zone.

Return value returns the Structure TM represents the current local time

The "Supplemental Instructions" function return value is a pointer, the actual memory is localtime internal static memory through static request, so through the localtime call after the return value is not used in a timely manner, it is likely to be overwritten by other threads localtime call. Other time functions, such as Asctime,asctime_r;ctime,ctime_r;gmtime,gmtime_r, are similar, so the _r version of the time function is thread-safe.

Mktime (Converts the time structure data to elapsed seconds)

"Header file" #include <time.h>

"Function prototype" time_t mktime (Strcut TM * timeptr);

The function Description Mktime () is used to convert the TM structure data referred to by the parameter timeptr to the number of seconds elapsed since January 1, 1970 0:0 0 seconds from the UTC time.

"Return value" returns the number of seconds elapsed

Difftime (two system time difference)

"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 time interval between two variables of type time_t

The time function of C library function

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.