liveBook · Manning

Gmtime_s

As explained in Modern C

gmtime_s is an Annex K C library function that converts a time_t value to a broken-down UTC time in a caller-provided object.

Convert a timestamp to UTC

time_t stamp = time(NULL);\nstruct tm utc;\nstruct tm *result = gmtime_s(&stamp, &utc);\n\nThe caller supplies both the time_t value and the struct tm object that receives the broken-down UTC time.

gmtime_s is an Annex K C library function that converts a time_t value into broken-down universal time, UTC. Its result object is supplied by the caller. section 8.5

TAKEAWAY: Choose gmtime_s for UTC and localtime_s for local time; mktime performs the corresponding local-time conversion in the opposite direction. section 8.5

How Modern C covers it

How deep it goes
Defines the UTC distinction and interface signature but does not detail struct tm fields or conversion internals.
Examples
Uses a time_t value, a caller-declared struct tm object, and the gmtime_s declaration.
What it assumes
Uses time_t and struct tm without detailing their definitions or the individual broken-down fields.
What you can do after
Apply it via the C library to obtain broken-down UTC time in storage owned by the caller.
How it connects
Contrasts UTC conversion with localtime_s and relates the local-time inverse operation to mktime.

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.