ILE C/C++ Run-Time Library Functions


localtime() -- Convert Time

Format

#include <time.h>
struct tm *localtime(const time_t *timeval);

Language Level: ANSI

Threadsafe: No. Use localtime_r() instead.

Description

The localtime() function converts a time value, in seconds, to a structure of type tm.

Note:
This function is locale sensitive.

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.

The time value is usually obtained by a call to the time() function.

Notes:

  1. The gmtime() and localtime() functions may use a common, statically allocated buffer for the conversion. Each call to one of these functions may destroy the result of the previous call. The ctime_r(), gmtime_r(), and localtime_r() functions do not use a common, statically-allocated buffer. These functions can be used in the place of the asctime(), ctime(), gmtime() and localtime() functions if reentrancy is desired.

  2. 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 that uses localtime()

This example queries the system clock and displays the local time.


#include <time.h>
#include <stdio.h>
 
int main(void)
{
   struct tm *newtime;
   time_t ltime;
 
   ltime = time(&ltime);
   newtime = localtime(&ltime);
   printf("The date and time is %s", asctime(newtime));}
 
/**************  If the local time is 3:00 p.m. May 31, 1993,  **********
*************************  output should be:  *********************
 
The date and time is Mon May 31 15:00:00 1993
*/

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]