C examples for time.h:mktime
function
<ctime> <time.h>
Convert tm structure to time_t
time_t mktime (struct tm * timeptr);
Parameter | Description |
---|---|
timeptr | Pointer to a tm structure. |
A time_t value corresponding to the calendar time passed as argument.
On error, a value of -1 is returned.
#include <stdio.h> #include <time.h> int main ()/* w ww.j av a 2 s .co m*/ { time_t rawtime; struct tm * timeinfo; int year, month ,day; const char * weekday[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; year = 2020; month = 11; day = 23; time ( &rawtime ); timeinfo = localtime ( &rawtime ); timeinfo->tm_year = year - 1900; timeinfo->tm_mon = month - 1; timeinfo->tm_mday = day; mktime ( timeinfo ); printf ("That day is a %s.\n", weekday[timeinfo->tm_wday]); return 0; }