mktime

convert local time to calendar time

Synopsis:

#include <time.h>
time_t mktime( struct tm *timeptr );

Description:

The mktime() function converts the local time information in the structure pointed to by timeptr into a calendar time (Coordinated Universal Time) with the same encoding used by the time() function.

The original values of the fields tm_sec, tm_min, tm_hour, tm_mday and tm_mon are not restricted to ranges described for struct tm. If these fields are not in their proper ranges, they are adjusted so that they are. Values for the fields tm_wday and tm_yday are computed after all the other fields have been adjusted.

The original value of tm_isdst is interpreted as follows:

negative
this field is computed as well.
0
daylight savings time is not in effect
positive
daylight savings time is in effect

Whenever mktime() is called, the tzset() function is also called.

Returns:

the converted calendar time

See also:

asctime(), clock(), ctime(), difftime(), gmtime(), localtime(), strftime(), time(), tzset()

The tm structure is described in the section “time.h” of the C Library Overview chapter.

Examples:

#include <stdio.h>
#include <time.h>

static const char *week_day[] = {
    "Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday"
};

void main()
  {
    struct tm new_year;

    new_year.tm_year  = 2001 - 1900;
    new_year.tm_mon   = 0;
    new_year.tm_mday  = 1;
    new_year.tm_hour  = 0;
    new_year.tm_min   = 0;
    new_year.tm_sec   = 0;
    new_year.tm_isdst = 0;
    mktime( &new_year );
    printf( "The next century begins on a %s\n",
         week_day[ new_year.tm_wday ] );
  }

produces the output:

The next century begins on a Monday

Classification:

ANSI

Systems:

All (except Netware, DOS/PM)