struct tm -> time_t converter wanted
Dave Decot
decot at hpisod2.HP.COM
Fri Oct 21 12:15:20 AEST 1988
> I was surprised to find no routine in the C library
> to convert a struct tm into a time_t. Is there
> such a routine floating around somewhere?
Probably, but if you're going to do one of these yourself, please do it
in the form described by ANSI C, so you can use that when you get an
ANSI compiler and libraries:
#include <time.h>
time_t mktime(timeptr)
struct tm *timeptr;
The mktime function converts the broken-down time, expressed as
local time, in the structure pointed to by timeptr into a calendar
time value with the same encoding as that of the values returned by
the [time()] function. The original values of the tm_wday and
tm_yday components of the structure are ignored, and the original
values of the other components are not restricted to the [normal
ranges of those members]. On successful completion, the values of
the tm_wday and tm_yday components of the structure are set
appropriately, and the other components are set to represent the
specified calendar time, but with their values forced [into the
normal ranges]; the final value of tm_mday is not set until tm_mon and
tm_year are determined.
If the calendar time cannot be represented, the function returns the
value (time_t)-1.
Dave Decot
decot at hpda
More information about the Comp.lang.c
mailing list