Syntax | #include <time.h> time_t mktime(struct tm *timeptr); | |
Description | The The two functions differ merely in the range of dates which can be displayed:
The struct tm { int tm_sec; /* Seconds [0, 61] */ int tm_min; /* Minutes [0, 59] */ int tm_hour; /* Hours [0, 23] */ int tm_mday; /* Day of the month [1, 31] */ int tm_mon; /* Month [0, 11] */ int tm_year; /* Years since 1900 */ int tm_wday; /* Days since Sunday [0, 6] */ int tm_yday; /* Days since January 1 [0, 365] */ int tm_isdst; /* Flag for daylight saving time */ }; Besides computing the calendar time, The original values of the components may be either greater than or less than the specified range. For example, a If BS2000 | |
Return val. | Number of seconds | |
if successful. | ||
| ||
if the calendar time cannot be represented. Furthermore, | ||
| BS2000 | |
For local times as of January 1, 1970, 00.00.00, the number of seconds that have elapsed since then (positive value). For local times prior to January 1, 1970, 00.00.00, the number of elapsed seconds up to that point (negative value). (End) | ||
Example | Which day of the week was July 4, 2001? #include <stdio.h> #include <time.h> struct tm time_str char daybuf[20] int main (void) { time_str.tm_year = 2001 - 1900; time_str.tm_mon = 7 - 1; time_str.tm_mday = 4; time_str.tm_hour = 0; time_str.tm_min = 0; time_str.tm_sec = 1; time_str.tm_isdst = -1; if (mktime ( &time_str) == -1) (void) puts (" -unknown-“); else { (void) strftime (daybuf, sizeof (daybuf), "%A", &time_str); } return 0; } | |
Note | As -1 is a permissible return value in a successful situation, an application wishing to check for error situations should set errno to 0 before calling the function. | |
See also |
|