Name
mktime
Synopsis
Determines the time represented by a struct tm
value
#include <time.h> time_tmktime
( struct tm *timeptr
);
The mktime()
function
calculates the local calendar time represented by the member values
in the object referenced by the pointer argument.
The type struct tm
is
defined in time.h as
follows:
struct tm { int tm_sec; /* Seconds (0-60; 1 leap second) */ int tm_min; /* Minutes (0-59) */ int tm_hour; /* Hours (0-23) */ int tm_mday; /* Day (1-31) */ int tm_mon; /* Month (0-11) */ int tm_year; /* Year (difference from 1900) */ int tm_wday; /* Day of week (0-6) */ int tm_yday; /* Day of year (0-365) */ int tm_isdst; /* Daylight saving time (-1, 0, 1) */ };
The member tm_isdst
is
equal to 0 if daylight saving time is not in effect, or 1 if it is.
A negative value indicates that the information is not available, in
which case mktime()
attempts to
calculate whether daylight saving time is applicable at the time
represented by the other members.
The mktime()
function
ignores the tm_wday
and tm_yday
members in determining the time,
but does use tm_isdst
. The other
members may contain values outside their normal ranges. Once it has
calculated the time represented, mktime()
adjusts the struct tm
members so that each one is
within its normal range, and also sets tm_wday
and tm_yday
accordingly. The return value is
the number of seconds from the epoch (usually midnight on January 1,
1970, UTC) to the time represented in the structure, or -1 to
indicate an error.
Example
time_t ...
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.