The C gmtime() function converts a time_t calendar value into a broken-down UTC time stored in struct tm. UTC does not apply the machine's local time-zone offset.
The returned pointer usually refers to shared static storage that a later gmtime(), localtime(), or related call may overwrite. Check for NULL before reading fields. Include <time.h>.
Syntax
Start with this concrete gmtime() call:
C
gmtime(&stamp);
Call
What it does
gmtime(&stamp);
Converts stamp to UTC fields in a library-owned struct tm.
Declare the required objects with the time types shown below, include <time.h>, and check the documented result before using output data.
Library declaration
C
struct tm *gmtime(const time_t *timer);
Parameters
Parameter
Description
timer
Pointer to the time_t calendar-time value to convert.
Return Value
Return Value
Description
struct tm *
Pointer to broken-down UTC fields in static storage.
NULL
The value cannot be represented as UTC broken-down time.
C Examples
Example 1 — Read UTC Fields
This example demonstrates gmtime() with a small, complete program and checks the relevant result before using it.