liveBook · Manning

Time zone

As explained in Modern C

UTC is Coordinated Universal Time, the internationally used reference time scale for civil timekeeping.

In C, gmtime_s converts a time_t value into broken-down time expressed as UTC, while localtime_s expresses the same value in the local time zone. UTC is the universal reference time used for civil timekeeping. section 8.5

Choosing the conversion

struct tm result; gmtime_s(&instant, &result); /* UTC */ localtime_s(&instant, &result); /* local time */ The two functions differ in the time zone assumed during conversion. localtime_s and mktime should normally be inverse operations; gmtime_s has no direct inverse counterpart. section 8.5

After conversion, strftime can format the struct tm using date and time specifiers. Locale settings, including preferred language or time zone, may influence selected output. section 8.5

How Modern C covers it

How deep it goes
Defines UTC and contrasts conversion functions, but defers detailed global-state interfaces and pointer rationale.
Examples
Uses gmtime_s, localtime_s, mktime, strftime, and format strings as concrete interfaces.
What it assumes
Assumes familiarity with C library time types such as time_t and struct tm.
What you can do after
Apply C library conversions to represent a timestamp as UTC or local broken-down time and format it as text.
How it connects
Connects time zones with UTC, time_t, struct tm, mktime, strftime, locale, and calendar time.

Also explained in

Compare how 4 books explain time zone →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.