LINUX study notes 10-time programming

Source: Internet
Author: User
A) the header file must be included: # include & lt; time. h & gt; B) time type: 1. greenwich Mean Time: 2. calendar Time: the time represented by the number of seconds passed by a standard time point. The essence is the number of seconds. c) obtain the calendar Time: time_ttime (time_t * tloc): returned... a) the header file must be included: # include
 
B) time type:
 
1. Greenwich Mean Time:
 
2. calendar time: the time represented by the number of seconds passed by a standard time point. The essence is the number of seconds.
 
C) obtain the calendar time: time_t time (time_t * tloc): returns the number of seconds.
 
1. T = time (NULL );
 
D) time conversion:
 
1. convert the calendar Time to Greenwich Mean Time: struct tm * gmtime (const time_t * timep)
 
A) timep: the address of the time variable used to save the time.
 
B) time_t t: defines the time variable.
 
2. convert calendar time to local time: struct tm * localtime (const time_t * timep)
 
3. save to the TM structure
 
Struct tm {
 
Int tm_sec;
 
Int tm_min;
 
Int tm_hour;
 
Int tm_mday;
 
Int tm_mon;
 
Int tm_year; relative value, + 1900
 
Int tm_wday;
 
Int tm_yday; the day of the current year
 
Int tm_isdst;}; daylight saving time
 
4. convert the time in tm format to a string for easy Display
 
A) Char * asctime (const struct tm * tm)
 
5. convert the calendar time to a local time string for easy Display
 
A) Char * ctime (const time_t * timep)
 
6. obtain the time difference from the early morning of the current day. it is often used for time consumption, end time, and initial time.
 
A) Int gettimeofday (struct timeval * TV, struct timezone * tz)
 
B) Struct timeval {used to store seconds
 
C) Int TV _sec; used to store seconds
 
D) Int TV _usec;}; used to store microseconds
 
7. enable the program to sleep for sec seconds:
 
A) Unsigned int sleep (unsigned int seconds)
 
8. program sleep usec microseconds:
 
A) void usleep (unsigned long seconds)

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.