Name
localtime
Synopsis
Converts a timer value into a year, month, day, hour, minute, second, and so on
#include <time.h> struct tm *localtime
( const time_t *timer
);
The localtime()
function
converts a numeric time value (usually a number of seconds since
January 1, 1970, but not necessarily) into the equivalent date and
time structure for the local time zone. To obtain similar values for
Coordinated Universal Time (UTC, formerly called Greenwich Mean
Time), use the function gmtime()
.
The function’s argument is not the number of seconds itself,
but a pointer to that value. Both the structure type struct tm
and the arithmetic type time_t
are defined in the header file
time.h. The tm
structure is described at gmtime()
in this chapter.
The argument most often passed to localtime()
is the current time, obtained
as a number with type time_t
by
calling the function time()
. The
type time_t
is usually defined in
time.h as equivalent to
long
or unsigned long
.
Example
See the example for gmtime()
in this
chapter.
See Also
asctime()
, difftime()
, gmtime()
, mktime()
, strftime()
, time()
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.