Functions
Time manipulationclock | Clock program (function) |
difftime | Return difference between two times (function) |
mktime | Convert tm structure to time_t (function) |
time | Get current time (function) |
Conversion:
asctime | Convert tm structure to string (function) |
ctime | Convert time_t value to string (function) |
gmtime | Convert time_t to tm as UTC time (function) |
localtime | Convert time_t to tm as local time (function) |
strftime | Format time to string (function) |
gmtime
<ctime>
struct tm * gmtime ( const time_t * timer );
Convert time_t to tm as UTC time
Uses the value pointed by timer to fill a tm structure with the values that represent the corresponding time, expressed as UTC (or GMT timezone).
Parameters
Return Value
A pointer to a tm structure with the time information filled in.
This structure is statically allocated and shared by the functions gmtime and localtime. Each time either one of these functions is called the contents of this structure is overwritten.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
mktime
<ctime>
time_t mktime ( struct tm * timeptr );
Convert tm structure to time_t
Interprets the contents of the tm structure pointed by timeptr as a calendar time expressed in local time. This calendar time is used to adjust the values of the members of timeptr accordingly and returned as an object of type time_t.
The original values of the members tm_wday and tm_yday of timeptr are ignored, and the ranges of values for the rest of its members are not restricted to their normal values (like tm_mday being between 1 and 31).
The object pointed by timeptr is modified, setting the tm_wday and tm_yday to their appropiate values, and modifying the other members as necessary to values within the normal range representing the specified time.
Parameters
-
timeptr
- Pointer to a tm structure that contains a calendar time broken down into its components (see tm).
Return Value
A time_t value corresponding to the calendar time passed as argument.
On error, a -1 value is returned.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
time_t
<ctime>
Time type
Type capable of representing times and support arithmetical operations.
This type is returned by the time function and is used as parameter by some other functions of the <ctime> header.
It is almost universally expected to be an integral value representing the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC. This is due to historical reasons, since it corresponds to a unix timestamp, but is widely implemented in C libraries across all platforms.
struct tm
<ctime>
Time structure
Structure containing a calendar date and time broken down into its components.
The structure contains nine members of type int, which are (in any order):
1 2 3 4 5 6 7 8 9 | |
The meaning of each is:
Member | Meaning | Range |
---|---|---|
tm_sec | seconds after the minute | 0-61* |
tm_min | minutes after the hour | 0-59 |
tm_hour | hours since midnight | 0-23 |
tm_mday | day of the month | 1-31 |
tm_mon | months since January | 0-11 |
tm_year | years since 1900 | |
tm_wday | days since Sunday | 0-6 |
tm_yday | days since January 1 | 0-365 |
tm_isdst | Daylight Saving Time flag |
localtime
<ctime>
struct tm * localtime ( const time_t * timer );
Convert time_t to tm as local time
Uses the time pointed by timer to fill a tm structure with the values that represent the corresponding local time.
Parameters
Return Value
A pointer to a tm structure with the time information filled in.
This structure is statically allocated and shared by the functions gmtime and localtime. Each time either one of these functions is called the content of this structure is overwritten.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |