mktime
Converts time to calendar format.
Defined in header <time.h>
Syntax
#include <time.h>
time_t mktime(struct tm *t);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ |
Remarks
Converts the time in the structure pointed to by t into a calendar time with the same format used by the time function. The original values of the fields tm_sec, tmjnin, tmjiour, tmjnday, and tmjnon are not restricted to the ranges described in the tm structure. If the fields are not in their proper ranges, they are adjusted. Values for fields tm_wday and tm_yday are computed after the other fields have been adjusted. If the calender time cannot be represented, mktime returns -1.
The allowable range of calender times is Jan 1 1970 00:00:00 to Jan 19 2038 03:14:07.
Return value
See Remarks.
See also
Example
#include <stdio.h>
#include <time.h>
char *wday[] = "Sunday", "Monday", "Tuesday", "Wednesday", Thursday", "Friday",
"Saturday ", "Unknown"};
int main (void)
struct tm time_check;
int year, month, day;
/* input year, month, and day to find the weekday for */
printf ("Year: ");
scanf ("%d", &year);
printf ("Month: ");
scanf ("%d", &month);
printf ("Day: ");
scanf {"%d", &day);
/* load the time_check structure with the data */
time_check.tm_year = year - 1900;
time_check.tm_mon = month - 1;
time_check.tm_mday = day;
time_check.tm_hour = 0
time_check.tm_min = 0
time_check.tm_sec = 1
time_check.tm_isdst - -1;
/* call mktime to fill in the structure's v/eekday field */
if (mktime(&time_check) -= -1)
time_check.tm_wday = 7;
/* print out the day of the week */
printf ("That day is a %s\n", wday[time_check.tm_wday]);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/time.h/mktime/
· short form /3.1/mktime/