преобразование даты и времени (date and time conversion)
Примеры (Examples)
Convert a Date-Plus-Time String to Broken-Down Time and Then into
Seconds
The following example demonstrates the use of strptime() to
convert a string into broken-down time. The broken-down time is
then converted into seconds since the Epoch using mktime().
#include <time.h>
...
struct tm tm;
time_t t;
if (strptime("6 Dec 2001 12:33:45", "%d %b %Y %H:%M:%S", &tm) == NULL)
/* Handle error */;
printf("year: %d; month: %d; day: %d;\n",
tm.tm_year, tm.tm_mon, tm.tm_mday);
printf("hour: %d; minute: %d; second: %d\n",
tm.tm_hour, tm.tm_min, tm.tm_sec);
printf("week day: %d; year day: %d\n", tm.tm_wday, tm.tm_yday);
tm.tm_isdst = -1; /* Not set by strptime(); tells mktime()
to determine whether daylight saving time
is in effect */
t = mktime(&tm);
if (t == -1)
/* Handle error */;
printf("seconds since the Epoch: %ld\n", (long) t);"