mktime
Syntax
Defined
in
Description
Example
6-56
#include
<time.h>
time_t
*mktime{timeptr)
struct
tm
*timeptr;
mktime.c
in
rts.src
Convert
to
Calendar
Time
The mktime function converts a broken-down time, expressed
as
local time,
into proper calendar time. The
timeptr
argument points
to
a structure that
holds the broken-down time.
The function ignores the original values
of
tm.....wday
and tm.....yday, and
does not restrict the other values in the structure. After successful com-
pletion,
tm.....wday
and tm.....yday
are
set appropriately, and the other com-
ponents in the structure have
values
within
the restricted ranges. The final
value
of
tm-mday
is
not
sent until
tm.....mon
and tm.....year
are
determined.
The return value
is
encoded
as
a value
of
type time-to If the calendar time
cannot
be
represented, the function returns the value -1.
This
example determines the day
of
the week that
July
4, 2001, falls on.
#include
<time.h>
static
const
char
*const
wday[]
= (
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
struct
tm
time-str;
time-str.tm.....year
time_str.tm-mon
time_str.tm-mday
time-str.tm.....hour
time_str.tm-min
time-str.tm.....sec
time-str.tm.....isdst
mktime(&time-str)
;
2001
-
1900;
7 ;
4 ;
0;
0;
1;
1;
printf
("result
is
%s\n",
wday[time-str.tm.....wday])i
/*
After
calling
this
function,
time-str.tm.....wday
contains
the
day
of
the
week
for
July
4,
2001
*/
For more information about the functions and types that the
time.
h
header declares,
see
Section
6.1
.10 on page 6 -
7.