The C mktime() function interprets a struct tm as local time and converts it to a time_t calendar value. It is the usual inverse of localtime().
The function also normalizes out-of-range fields and writes the normalized values back to the structure. Set tm_isdst to -1 when the library should determine daylight-saving status. Include <time.h>.
Syntax
Start with this concrete mktime() call:
C
mktime(&local);
Call
What it does
mktime(&local);
Interprets and normalizes local, then returns its calendar-time value.
Declare the required objects with the time types shown below, include <time.h>, and check the documented result before using output data.
Library declaration
C
time_t mktime(struct tm *time_ptr);
Parameters
Parameter
Description
time_ptr
Pointer to a writable struct tm interpreted as local time.
Return Value
Return Value
Description
time_t value
Calendar-time representation of the normalized local date and time.
(time_t)-1
The local time cannot be represented.
C Examples
Example 1 — Build a Local Date
This example demonstrates mktime() with a small, complete program and checks the relevant result before using it.