Home

gmtime

gmtime is a function name used in several programming environments to convert a time value to a broken-down representation of Coordinated Universal Time (UTC). In general, it takes a time value such as a timestamp and returns the components of the corresponding calendar date and time expressed in UTC (year, month, day, hour, minute, second).

In C, the prototype is struct tm *gmtime(const time_t *timep). It returns a pointer to a statically

In Python, time.gmtime([seconds]) returns a time.struct_time in UTC. If seconds is omitted, the current time is

See also: time.localtime, mktime, time module utilities that handle local time and conversions between time representations.

allocated
struct
tm
containing
fields
such
as
tm_year,
tm_mon,
tm_mday,
tm_hour,
tm_min,
tm_sec,
tm_wday,
and
tm_yday.
The
time
is
in
UTC,
and
tm_isdst
is
typically
0.
The
function
may
return
NULL
if
the
time
value
cannot
be
represented.
Because
it
uses
static
storage,
successive
calls
overwrite
previous
results,
and
the
function
is
not
thread-safe.
Portable
applications
often
prefer
gmtime_r
(POSIX)
or
gmtime_s
(Windows)
for
thread
safety.
The
reverse
operation,
converting
a
UTC
broken-down
time
to
a
time
value,
is
performed
by
timegm
(GNU)
or
_mkgmtime
on
Windows.
used.
The
result
is
a
new
object,
and
the
call
is
thread-safe.
It
is
commonly
used
for
formatting
or
for
converting
timestamps
to
calendar
fields
in
UTC.