struct tm * gmtime (const time_t * timer);
Convert time_t to tm as UTC time
Uses the value pointed by timer to fill a tm structure with the values that represent the corresponding time, expressed as a UTC time (i.e., the time at the GMT timezone).
For a local time alternative, see localtime.
- Pointer to an object of type time_t that contains a time value.
time_t is an alias of a fundamental arithmetic type capable of representing times as returned by function time.
A pointer to a tm structure with its members filled with the values that correspond to the UTC time representation of timer.
The returned value points to an internal object whose validity or value may be altered by any subsequent call to gmtime or localtime.
/* gmtime example */
#include <stdio.h> /* puts, printf */
#include <time.h> /* time_t, struct tm, time, gmtime */
#define MST (-7)
#define UTC (0)
#define CCT (+8)
int main ()
struct tm * ptm;
time ( &rawtime );
ptm = gmtime ( &rawtime );
puts ("Current time around the World:");
printf ("Phoenix, AZ (U.S.) : %2d:%02d\n", (ptm->tm_hour+MST)%24, ptm->tm_min);
printf ("Reykjavik (Iceland) : %2d:%02d\n", (ptm->tm_hour+UTC)%24, ptm->tm_min);
printf ("Beijing (China) : %2d:%02d\n", (ptm->tm_hour+CCT)%24, ptm->tm_min);
Current time around the World:
Phoenix, AZ (U.S.) : 8:22
Reykjavik (Iceland) : 15:22
Beijing (China) : 23:22
The function accesses the object pointed by timer.
The function also accesses and modifies a shared internal object, which may introduce data races on concurrent calls to gmtime and localtime. Some libraries provide an alternative function that avoids this data race: gmtime_r (non-portable).
No-throw guarantee: this function never throws exceptions.
- Convert tm structure to string (function)
- Convert time_t value to string (function)
- Convert time_t to tm as local time (function)
- Convert tm structure to time_t (function)
- Get current time (function)