System time represents calendar time in a form suited to human interpretation: dates, clock times, appointments, and birthdays. In C, <time.h> supplies a current timestamp as time_t; two timestamps can be compared with difftime to express elapsed time. section 8.6 section 8.9
time_t time(time_t *t);
double difftime(time_t time1, time_t time0);
time_t mktime(struct tm tm[1]);
size_t strftime(char s[static 1], size_t max,
char const format[static 1],
struct tm const tm[static 1]);
int timespec_get(struct timespec ts[static 1], int base);
int timespec_getres(struct timespec ts[static 1], int base);
These declarations provide the core C interfaces for obtaining, comparing, converting, formatting, and querying calendar times. section 8.6
A calendar time can be represented in two complementary ways:
- Use time_t for an arithmetic timestamp representing a calendar time and difftime for the difference between two timestamps. section 8.6
- Use struct tm for hierarchical human fields such as year, month, day, weekday, and seconds. section 8.6
- Remember that most struct tm fields begin at zero: tm_mon is zero-based, tm_wday 0 means Sunday, and tm_year requires adding 1900. section 8.6
- Use mktime to normalize hierarchical fields, calculate tm_wday and tm_yday, update daylight-saving status when requested, and return a time_t. section 8.6
Reading struct tm fields
A struct tm with tm_mon equal to 0 denotes January, while tm_mday equal to 1 denotes the first day of the month. A tm_year value represents the Gregorian year minus 1900, so interpreting the fields requires applying the documented exceptions rather than treating every member alike. section 8.6


