Home

localtime

Localtime is a function in the C standard library that converts a time value to a broken-down calendar time in the system’s local time zone. The input is a pointer to time_t, and the function returns a pointer to a statically allocated struct tm containing fields such as tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, and tm_isdst. The resulting values reflect the local offset from UTC and any daylight saving time (DST) adjustments as determined by the system’s time zone data.

The function uses the system’s time zone settings, which may be influenced by environment configuration (for

Because localtime returns a pointer to a static internal buffer, its contents can be overwritten by subsequent

Related functions include gmtime, which converts time_t to Coordinated Universal Time (UTC) without regard to local

example,
the
TZ
variable
in
many
Unix-like
systems)
or
platform-specific
time
zone
databases.
Local
time
can
be
ambiguous
or
invalid
during
DST
transitions,
and
tm_isdst
indicates
DST
status
when
available.
calls.
This
makes
localtime
non-thread-safe
in
many
environments.
To
obtain
thread-safe
results,
many
systems
provide
localtime_r
(POSIX)
or
localtime_s
(Windows),
which
store
the
result
in
a
user-supplied
struct
tm.
time
zone,
and
mktime,
which
converts
a
local
broken-down
time
back
to
time_t
using
the
local
time
rules.
The
concept
of
local
time
and
its
DST
rules
can
vary
by
region
and
over
time
as
time
zone
databases
are
updated.