gmtime_r converts a time_t value into broken-down Coordinated Universal Time (UTC), storing the result in caller-provided storage. section 8.6
Store a UTC breakdown
time_t timestamp = time(NULL);\nstruct tm utc;\ngmtime_r(×tamp, &utc);\n\nAfter the call, utc holds the broken-down UTC representation of timestamp. section 8.6
Keep these distinctions in mind:
- Use localtime_r for broken-down local time; gmtime_r assumes UTC. section 8.6
- Pair gmtime_r with timegm when converting between time_t and broken-down UTC. section 8.6
- Prefer reentrant interfaces over traditional functions that operate on global state. 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 the declarations of gmtime_r, localtime_r, and timegm. section 8.6
