Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

mktime, mktime64 - Convert date and time (calendar function)

&pagelevel(4)&pagelevel


Definition

#include <time.h>

time_t mktime(struct tm *tm_p);
time_t mktime64(struct tm *tm_p);

mktime and mktime64 convert the date and time which the user specifies in a structure of the type tm to a time specification which is displayed as the number of seconds which have passed since the reference date (epoch). Dates before the reference date are returned as negative values. The earliest displayable date with mktime is 12/13/1901 20:45:52 local time and 01/01/1900 00:00:00 with mktime64.

In the calculation mktime and mktime64 complement the tm structure with the values for weekday (0-6) and day since the start of the year (0-365) and adjust the values of the other components to the ranges of values provided by default (see also the parameter description).

By default, the reference date is always 1/1/1970 00:00:00.

If the calendar time cannot be displayed because of missing specifications in the input parameter, mktime/mktime64 supplies the return value -1. In the case of mktime this also applies for dates before12/13/1901 20:45:52 and after 01/19/2038 03:14:07.

mktime64 can display dates up to 3/18/4317 02:44:48.

Parameters

struct tm *tm_zg

Pointer to a structure of type tm which is supplied by the user with the date and time and is then updated by mktime/mktime64. The default value ranges are given in parentheses.

int   tm_sec;           seconds (0-59)
int   tm_min;           minutes (0-59)
int   tm_hour;          hours (0-23)
int   tm_mday;          day of the month (1-31)
int   tm_mon;           months since the start of the year (0-11)
int   tm_year;          years since 1900
int   tm_wday;          weekday (0-6, Sunday=0)
int   tm_yday;          days since January 1 (0-365)
int   tm_isdst;         daylight saving time flag:
                        0    daylight saving time is not in effect
                        >0   daylight saving time is in effect
                        <0   information is not available
  1. User-specified date and time entries

    The components tm_wday and tm_yday do not need to be supplied because mktime ignores them when calculating time_t and then supplies them with the appropriate values. All other components must be assigned a value. These values ​​are not limited to the standard value ranges mentioned above, i.e. they can also be larger or smaller.

    Examples for this:

    -1 in tm_hour means 1 hour befor midnight
    0 in tm_mday means the day preceding the current month,
    -2 in tm_mon means 2 months before January of the tm_year.

  2. Structure updating by mktime

    The components tm_wday and tm_yday are set to the values that match the user specifications.
    The other components are assigned so that their values correspond to the abovementioned default ranges.
    The value of tm_mday is not assigned unless tm_mon and tm_year have been defined..

Return val.

Integer>0

for local times after the reference date (epoch): the number of seconds which have elapsed since then (positive value).


Integer<0

for local times prior to the reference date (epoch): the number of seconds which have elapsed up to that point (negative value)


(time_t) - 1

if the time cannot be represented.   Furthermore,  errno  is set to   EOVERFLOW .

Note

As -1 is a permissible return value in a successful situation, an application wishing to check for error situations should set errno to 0 before calling the function.
If -1 is returned, the application should check if errno is non-zero.

See also

asctime, ctime, ctime64, difftime, difftime64, ftime, ftime64, gmtime, gmtime64, localtime, localtime64, time, time64