mktime [ HP C/iX Library Reference Manual ] MPE/iX 5.0 Documentation
HP C/iX Library Reference Manual
mktime
Converts a calendar time value of type tm to a time value in time_t.
Syntax
#include <time.h>
time_t mktime(struct tm *timeptr);
Parameters
timeptr A pointer to a structure of type tm, as defined in
<time.h>.
Return Values
x The value pointed to by timeptr, as a type time_t.
Description
The mktime function converts the broken-down time in the structure
pointed to by timeptr into a calendar time value. The file pointed to by
timeptr is expressed in the local time. The return value has the same
encoding as the values returned by the time function.
The original values of the tm_wday and tm_yday components of the
structure (shown below) are ignored.
A positive or zero value for tm_isdst causes the mktime function to
presume initially that Daylight Saving Time, respectively, is or is not
in effect. A negative value for tm_isdst causes the mktime function to
attempt to determine whether Daylight Saving Time is in effect for the
specified time. The original values of the tm components are not
restricted to the ranges indicated below.
On successful completion, the values of the tm_wday and tm_yday
components of the structure are set appropriately. The values of the
other components are set to represent the specified calendar time, but
with their values forced into valid ranges.
The final value of tm_mday is not set unless tm_mon and tm_year are
determined.
The tm data structure is declared in <time.h>. The declaration is shown
below:
struct tm {
int tm_sec; /* seconds after the minute (0 through 59 */
int tm_min; /* minutes after the hour (0 through 59) */
int tm_hour; /* hours since midnight (0 through 23) */
int tm_mday; /* day of the month (1 through 31) */
int tm_mon; /* month of the year (0 through 11) */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday (0 through 6) */
int tm_yday; /* day of the year (0 through 365) */
int tm_isdst; /* daylight savings time flag (1 = dst */
};
By default, mktime adjusts the returned value to the Eastern Standard
Time (EST) zone. You may override this default behavior by using the
MPE/iX command SETVAR TZ name. Time zone names, and the format of
TZTAB.LIB.SYS file containing time zone offsets from GMT are listed in
appendix A, "Time Zones."
Example
What day of the week is July 4, 2001?
#include <stdio.h>
$include <time.h>
static const char *const wday[] = {
"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday",
"Saturday", "-unknown"
};
struct tm time_str;
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(1:01:46 AM_str) == -1)
time_str.tm_wday = 7;
printf("%s\n", wday[time_str.tm_wday]);
See Also
clock(), difftime(), time(), ANSI C 4.12.2.3, POSIX.1 8.1
MPE/iX 5.0 Documentation