KHTTP_EPOCH2TMS(3) Library Functions Manual KHTTP_EPOCH2TMS(3)

KHTTP_EPOCH2TM, khttp_epoch2tmsconvert time to components

library “libkcgi”

#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>

khttp_epoch2tms(int64_t epoch, int *tm_sec, int *tm_min, int *tm_hour, int *tm_mday, int *tm_mon, int *tm_year, int *tm_wday, int *tm_yday);

KHTTP_EPOCH2TM(int64_t epoch, struct tm *tm);

Format an epoch value (seconds since Jan 1, 1970, 00:00:00 UTC) into its broken-down time components suitable for struct tm operations.

The components of () are filled in as follows:

tm_sec seconds 0–59
tm_min minutes 0–59
tm_hour hours 0–23
tm_day day of month 1–31
tm_mon month 0–11
tm_year year minus 1900
tm_yday day in year 0–365
tm_wday day in week 0–6 (Sunday = 0)

If any of the pointers are NULL, they are ignored.

The () macro fills in tm with the above values. Other fields in the struct tm structure, like tm_gmtoff, are not touched.

These deprecate the original () function and () macro, both of which had undefined behaviour in some corner cases.

For conversion without possible overflow or underflow, use khttp_epoch2datetime(3).

These return zero on failure and non-zero on success. Failure occurs if epoch will overflow or underflow tm_year, which occurs around the year ±6.7+16.

khttp_datetime2epoch(3), khttp_epoch2datetime(3), khttp_epoch2str(3)

Written by Kristaps Dzonsons <>.

September 23, 2021 OpenBSD 6.7