liveBook · Manning

Localtime_r

As explained in Modern C, Third Edition

localtime_r is a C time-conversion function that stores a time_t value as broken-down local time.

localtime_r converts a time_t value into broken-down local time, storing the result in caller-provided struct tm storage. Its local-time interpretation distinguishes it from gmtime_r, which produces UTC. section 8.6

Interface shape

struct tm *localtime_r(const time_t *timer, struct tm *buf);\n\nThe input points to a time_t value; buf receives the broken-down local-time result. The paired conversion localtime_r/mktime should normally be inverse operations. section 8.6

time_t timegm(struct tm *timeptr);
struct tm *gmtime_r(const time_t *timer, struct tm *buf);
struct tm *localtime_r(const time_t *timer, struct tm *buf);

Compare localtime_r with gmtime_r and timegm through their declarations. section 8.6

How Modern C, Third Edition covers it

How deep it goes
Defines the conversion and contrasts local time with UTC, but does not detail struct tm fields or error handling.
Examples
Uses function declarations and the localtime_r/mktime inverse pair as its concrete illustrations.
What it assumes
Assumes familiarity with time_t, struct tm, pointers, and local-versus-UTC time; does not teach calendar structure from zero.
What you can do after
Apply localtime_r to store a time_t value as broken-down local time in supplied storage.
How it connects
Ties localtime_r to time_t, struct tm, gmtime_r, mktime, timegm, and time zones.

Related concepts

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