Time

Overview

The standard <time.h> header provides a few different types for measuring time. The only time base required by the C standard is TIME_UTC.

Processor Time

The clock_t type is an arithmetic type that holds an approximation of some active processing time. To determine the time spent in seconds, one should divide the value of an object with type clock_t by CLOCKS_PER_SEC.

The range and precision of times representable in clock_t is implementation-defined.

Calendar Time

The struct tm structure holds the components of a calendar time. The tm structure must contain at least the following members:

int tm_sec; // seconds after the minute -- [0, 60]
int tm_min; // minutes after the hour -- [0, 59]
int tm_hour; // hours since midnight -- [0, 23]
int tm_mday; // day of the month -- [1, 31]
int tm_mon; // months since January -- [0, 11]
int tm_year; // years since 1900
int tm_wday; // days since Sunday -- [0, 6]
int tm_yday; // days since January 1 -- [0, 365]
int tm_isdst; // Daylight Saving Time flag

Timestamps

The time_t type is used to represent timestamps, usually in the granularity of seconds. A time_t value of 0 refers to the epoch. This is usually January 1st, 1970.

The range and precision of times representable in time_t is implementation-defined.

Intervals

The struct timespec structure holds intervals specified in seconds and nanoseconds. The timespec structure must contain at least the following members:

time_t tv_sec; // whole seconds -- >= 0
/* implementation-defined */ tv_nsec; // nanoseconds -- [0, 999999999]
Powered by Forestry.md