[Previous]
[Contents]
[Next]

localtime(), _localtime()

convert calendar time to local time

Synopsis:

#include <time.h>
struct tm * localtime( const time_t *timer );
struct tm *_localtime( const time_t *timer,
                       struct tm *tmbuf );

Description:

The localtime() functions convert the calendar time pointed to by timer into local time, storing the information in a structure of type 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 (GMT)).

The _localtime() function places the converted time in the tm structure pointed to by tmbuf, and the localtime() function places the converted time in a static structure that is re-used each time localtime() is called.

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

Returns:

A pointer to a tm structure containing the time information. This structure is described in the section on <time.h> in the Header Files chapter.

Examples:

#include <stdio.h>
#include <time.h>

void main()
  {
    time_t time_of_day;
    char buf[26];
    struct tm tmbuf;

    time_of_day = time( NULL );
    _localtime( &time_of_day, &tmbuf );
    printf( "It is now: %s", _asctime( &tmbuf, buf ) );
  }

produces the output:

It is now: Sat Mar 21 15:58:27 1987

Classification:

ANSI
Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

asctime(), clock(), ctime(), difftime(), gmtime(), mktime(), strftime(), time(), tzset()


[Previous]
[Contents]
[Next]