determine the current calendar time
#include <time.h> time_t time( time_t *tloc );
The time() function determines the current calendar time, and encodes it into the type time_t.
The time represents the time since January 1, 1970 Coordinated Universal Time (UTC) (formerly known as Greenwich Mean Time (GMT)). 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 section “The TZ Environment Variable” in the chapter C Library Overview for a discussion of how to set the time zone.
The time() function returns the current calendar time. If tloc is not NULL, the current calendar time is also stored in the object pointed to by tloc.
asctime(), clock(), ctime(), difftime(), gmtime(), localtime(), mktime(), strftime(), tzset()
#include <stdio.h> #include <time.h> void main() { time_t time_of_day; time_of_day = time( NULL ); printf( "It is now: %s", ctime( &time_of_day ) ); }
produces the output:
It is now: Fri Dec 25 15:58:42 1987
ANSI, POSIX 1003.1
All (except Netware, DOS/PM)