A) the header file must be included: # include <time. h>
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)