C time gmtime() Function
Example
Print the current hour and minute in UTC:
time_t now = time(NULL);
struct tm *t = gmtime(&now);
printf("Hour (UTC): %d\n", t->tm_hour);
printf("Minute (UTC): %d\n", t->tm_min);
Definition and Usage
The gmtime() function converts a time_t value into a struct tm in UTC (Coordinated Universal Time, the same time everywhere in the world).
It works like localtime(), but it does not use the time zone of the computer.
A struct tm holds the parts of a date and time in separate members, like tm_hour and tm_min. See all members on the C time Library page.
The gmtime() function is defined in the <time.h> header file.
Syntax
struct tm *gmtime(const time_t *timer);
Parameter Values
| Parameter | Description |
|---|---|
| timer | Required. A pointer to a time_t value, for example from time(). |
Technical Details
| Returns: | A pointer to a struct tm with the date and time in UTC, or NULL if the time cannot be converted. The struct is shared, so the next call to gmtime() or localtime() overwrites it. |
|---|
Related Pages
Read more about dates and times in our C Date and Time Tutorial.