< c‎ | chrono
Revision as of 03:47, 9 October 2013 by Eendy (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Defined in header <time.h>
time_t mktime( tm* time );

Converts local calendar time to a time since epoch as a time_t object. time->tm_wday and time->tm_yday are ignored. The values in time are not checked for being out of range.

A negative value of time->tm_isdst causes mktime to attempt to determine if Daylight Saving Time was in effect.

If the conversion is successful, the time object is modified. All fields of time are updated to fit their proper ranges. time->tm_wday and time->tm_yday are recalculated using information available in other fields.


[edit] Parameters

time - pointer to a tm object specifying local calendar time to convert

[edit] Return value

time since epoch as a time_t object on success or -1 if time cannot be represented as a time_t object.

[edit] Example

Display the time 100 months ago

#include <stdio.h>
#include <time.h>
int main()
    time_t t = time(NULL);
    struct tm *tmptr = localtime(&t);
    printf("Today is           %s", asctime(tmptr));
    tmptr->tm_mon -= 100;
    printf("100 months ago was %s", asctime(tmptr));


Today is           Wed Oct  9 10:47:25 2013
100 months ago was Thu Jun  9 10:47:25 2005

[edit] See also

converts time since epoch to calendar time expressed as local time
(function) [edit]