Updated: May 06, 2022

Determine the current calendar time


#include <time.h>

time_t time( time_t * tloc );


NULL, or a pointer to a time_t object where the function can store the current calendar time.



Use the -l c option to qcc to link against this library. This library is usually included automatically.


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)).

You typically use the date command to set the computer's internal clock using Coordinated Universal Time (UTC). Use the TZ environment variable or _CS_TIMEZONE configuration string to establish the local time zone. For more information, see Setting the time zone in the Configuring Your Environment chapter of the QNX Neutrino User's Guide.


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.


#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


ANSI, POSIX 1003.1

Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes