liveBook · Manning

Localtime_s

As explained in Modern C

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

localtime_s converts a time_t value into broken-down local time and stores the result in an object supplied by the caller. It is an Annex K alternative to traditional interfaces that operate on global state. section 8.5

The interface

struct tm *localtime_s(time_t const timer[restrict static 1], struct tm result[restrict static 1]); The timer argument identifies the time_t value to convert; result identifies caller-provided storage for the broken-down local time. The conversion uses local time-zone assumptions, unlike gmtime_s, which expresses the result as UTC. Under normal circumstances, localtime_s and mktime are inverse operations. section 8.5

How Modern C covers it

How deep it goes
Defines the conversion, storage destination, time-zone distinction, and mktime relationship without detailing implementation internals.
Examples
Uses the localtime_s declaration and contrasts local-time conversion with gmtime_s's UTC conversion.
What it assumes
Assumes familiarity with time_t and struct tm while identifying caller-provided storage through the function declaration.
What you can do after
Apply it via the Annex K C library interface to store a time_t conversion in caller-provided broken-down-time storage.
How it connects
Connects time_t, struct tm, mktime, gmtime_s, and UTC through opposing time-conversion directions.

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.