[Previous] [Contents] [Index] [Next]

time()

Determine the current calendar time

Synopsis:

#include <time.h>

time_t time( time_t * tloc );

Library:

libc

Description:

The time() function takes a pointer to time_t as an argument and returns a value of time_t on exit. The returned value is the current calendar time, in seconds, since the Unix Epoch, 00:00:00 January 1, 1970 Coordinated Universal Time (UTC) (formerly known as Greenwich Mean Time (GMT)).

The time set on the computer with the date command reflects UTC. The TZ environment variable is used to establish the local time zone. See "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:

The current calendar time, in seconds, since 00:00:00 January 1, 1970 Coordinated Universal Time (UTC). If tloc isn't NULL, the current calendar time is also stored in the object pointed to by tloc.

Examples:

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

int main( void )
  {
    time_t time_of_day;

    time_of_day = time( NULL );
    printf( "It is now: %s", ctime( &time_of_day ) );
    return EXIT_SUCCESS;
  }

produces the output:

It is now: Wed Jun 30 09:09:33 1999

Classification:

ANSI

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

See also:

asctime(), asctime_r(), clock(), clock_gettime(), ctime(), difftime(), gmtime(), localtime(), localtime_r(), mktime(), strftime(), tzset()


[Previous] [Contents] [Index] [Next]