convert local time to calendar time
#include <time.h> time_t mktime( struct tm *timeptr );
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:
Whenever mktime() is called, the tzset() function is also called.
the converted calendar time
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.
#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
ANSI
All (except Netware, DOS/PM)