CKTIS / C
gmtime — C23 time function
`gmtime(timer)` from `<time.h>` converts the designated `time_t` calendar-time value to broken-down UTC in a `struct tm` object. It returns a pointer to the result, or null when UTC is unavailable or the value cannot be represented.
Version: C23
Syntax
struct tm *gmtime(const time_t *timer);gmtime(timer) from <time.h> converts the designated time_t calendar-time value to broken-down UTC in a struct tm object. It returns a pointer to the result, or null when UTC is unavailable or the value cannot be represented.
The example passes a time_t value of zero and, in the Unix-epoch environment, prints 1970-01-01 4 0: the date, Thursday as tm_wday == 4, and the first day of the year as tm_yday == 0. C does not define the numeric meaning of zero time_t, so this exact date is a property of the example platform.
The result may designate a shared static object overwritten by later gmtime or localtime calls, so copy needed fields before another call and synchronize threads; C23 also provides gmtime_r. tm_mon and tm_yday are zero-based, tm_year counts from 1900, and tm_isdst is zero for UTC. Always test for null before dereferencing.
Examples
#include <stdio.h>
#include <time.h>
int main(void){time_t value=(time_t)0;struct tm *utc=gmtime(&value);if(!utc)return 1;printf("%04d-%02d-%02d %d %d\n",utc->tm_year+1900,utc->tm_mon+1,utc->tm_mday,utc->tm_wday,utc->tm_yday);return 0;}
Result
1970-01-01 4 0
The example passes a `time_t` value of zero and, in the Unix-epoch environment, prints `1970-01-01 4 0`: the date, Thursday as `tm_wday == 4`, and the first day of the year as `tm_yday == 0`. C does not define the numeric meaning of zero `time_t`, so this exact date is a property of the example platform.