On this page
gmtime
Prev: strftime | Up: time.h | Next: asctime
Rel: time.h, math, time & assert Guide
Ref: cppreference — gmtime
Tags: #public #prog #c #stdlib #time #tier/standard
Include
#include <time.h>
Signature & Overview
struct tm *gmtime(const time_t *timer); /* also localtime */
Converts time_t to UTC broken-down struct tm.
Notes & Pitfalls
- Returns pointer to a static struct (NOT thread-safe): Use
gmtime_r()(POSIX) orgmtime_s()(C11/Windows) in multi-threaded code.
Example
#include <assert.h>
#include <time.h>
int main(void) {
time_t epoch = 0;
struct tm *utc = gmtime(&epoch);
assert(utc != NULL && utc->tm_year + 1900 == 1970);
}
Linked from
Related notes
- tuts/c/stdlib/time/asctime Linked here; links to this page; shared tags: #c, #prog, #stdlib, #tier, #time
- tuts/c/stdlib/time/strftime Linked here; links to this page; shared tags: #c, #prog, #stdlib, #tier, #time
- tuts/c/stdlib/time Linked here; links to this page; shared tags: #c, #prog, #stdlib, #time
- tuts/c/stdlib/math_time_and_assert Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/time/time shared tags: #c, #prog, #stdlib, #tier, #time
- tuts/c/stdlib/time/timespec_get shared tags: #c, #prog, #stdlib, #tier, #time
- tuts/c/stdlib/assert/assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/static_assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isalpha shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isdigit shared tags: #c, #prog, #stdlib, #tier