List of commonly used time functions for c++ learning

List of commonly used time functions for c++ learning

Kind of time

Local time : UTC + time zone difference = local time

UTC (Coordinated Universal Time) : A time standard based on the Earth's rotation.

GMT (Universal Time, Greenwich Mean Time) : Universal time corrected for periodic differences in Earth's rotational speed.

GMT/UTC are generally treated as the same time.

Get Time

To get the current time, you can use the time function, which returns the current calendar time of the system, expressed in seconds since January 1, 1970, or returns 1 if the system has no time.

The function prototype is: time_t time(time_t *time), time_t is actually a time storage method under Linux.

There are two common storage methods for storing time under Linux, one is the number of seconds elapsed from 1970 to the present, and the other is to use a structure to store the year/month/day/hour, minute, and second respectively. Under Linux, timeval can also be used to represent more precise seconds, and the timeval structure can represent microseconds. tm is a structure that stores time, which can be accurate to the second.

time shift

convert time_t to string

The time_t variable can be converted to a string using the ctime function.

convert time_t to tm

A time_t can be converted to a tm structure using the localtime function.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325028134&siteId=291194637