localtime() — Convert Time
Format
#include <time.h>
struct tm *localtime(const time_t *timeval);
Language Level
ANSI
Threadsafe
No
Use localtime_r()
instead.
Locale Sensitive
The behavior of this function might be affected by the LC_TOD category of the current locale.
Description
The localtime()
function
converts a time value, in seconds, to a structure of type tm.
The localtime()
function
takes a timeval assumed to be Universal
Coordinate Time (UTC) and converts it to job locale time. For this
conversion localtime()
checks
the current locale setting for local time zone and daylight saving
time (DST). If these values are not set in the current locale, localtime()
gets
the local time zone and daylight saving time (DST) settings from
the current job. Once converted, the time is returned in a structure
of type tm. If the DST is set in the locale but the time zone
information is not, the DST information in the locale is ignored.
time()
function.
- The
gmtime()
andlocaltime()
functions can use a common, statically allocated buffer for the conversion. Each call to one of these functions might destroy the result of the previous call. Thectime_r()
,gmtime_r()
, andlocaltime_r()
functions do not use a common, statically allocated buffer. These functions can be used in place of theasctime()
,ctime()
,gmtime()
andlocaltime()
functions if reentrancy is desired. - Calendar time is the number of seconds that have elapsed since EPOCH, which is 00:00:00, January 1, 1970 Universal Coordinate Time (UTC).
Return Value
The localtime()
function
returns a pointer to the structure result. There is no error return
value.
Example
#include <time.h>
#include <stdio.h>
int main(void)
{
struct tm *newtime;
time_t ltime;
ltime = time(<ime);
newtime = localtime(<ime);
printf("The date and time is %s", asctime(newtime));}
/************** If the local time is 3 p.m. February 15, 2008, **********
************************* the output should be: *********************
The date and time is Fri Feb 15 15:00:00 2008
*/
Related Information
- asctime() — Convert Time to Character String
- asctime_r() — Convert Time to Character String (Restartable)
- ctime() — Convert Time to Character String
- ctime64() — Convert Time to Character String
- ctime64_r() — Convert Time to Character String (Restartable)
- ctime_r() — Convert Time to Character String (Restartable)
- gmtime() — Convert Time
- gmtime64() — Convert Time
- gmtime64_r() — Convert Time (Restartable)
- gmtime_r() — Convert Time (Restartable)
- localtime_r() — Convert Time (Restartable)
- localtime64() — Convert Time
- localtime64_r() — Convert Time (Restartable)
- mktime() — Convert Local Time
- mktime64() — Convert Local Time
- setlocale() — Set Locale
- time() — Determine Current Time
- time64() — Determine Current Time
- <time.h>