[Previous] [Contents] [Next]

localtime()

Convert calendar time to local time

Synopsis:

#include <time.h>

struct tm *localtime( const time_t *timer );

Library:

libc

Description:

The localtime() function converts the calendar time pointed to by timer into local time, storing the information in a struct tm. Whenever localtime() is called, the tzset() function is also called.

The calendar time is usually obtained by using the time() function. That time is Coordinated Universal Time (UTC, formerly known as Greenwich Mean Time or GMT).

The localtime() function places the converted time in a static structure that's reused each time localtime() is called. Use localtime_r() if you want a thread-safe version.

The time set on the computer with the date command reflects Coordinated Universal Time (UTC). The environment variable TZ is used to establish the local time zone. See the section "The TZ environment variable" in the Global Data and the TZ Environment Variable chapter for a discussion of how to set the time zone.

Returns:

A pointer to the static struct tm containing the time information.

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread No

See also:

asctime(), asctime_r(), clock(), ctime(), ctime_r(), difftime(), gmtime(), gmtime_r(), mktime(), localtime_r(), strftime(), time(), tm, tzset()


[Previous] [Contents] [Next]