convert calender time to local time
#include <time.h> char * ctime( const time_t *timer ); char *_ctime( const time_t *timer, char *buf );
The ctime() functions convert the calendar time pointed to by timer to local time, in the form of a string. The ctime() function is equivalent to
asctime( localtime ( timer ) )
The ctime() functions convert the time into a string containing exactly 26 characters. This string has the form shown in the following example:
Sat Mar 21 15:58:27 1987\n\0
All fields have a constant width. The new-line character '\n' and the null character '\0' occupy the last two positions of the string.
The ANSI function ctime() places the result string in a static buffer that is re-used each time ctime() or asctime() is called. The non-ANSI function _ctime() places the resulting string in the buffer pointed to by buf.
Whenever the ctime() functions are 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 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 pointer to the string containing the local time.
asctime(), clock(), difftime(), gmtime(), localtime(), mktime(), strftime(), time(), tzset()
#include <stdio.h> #include <time.h> void main() { time_t time_of_day; char buf[26]; time_of_day = time( NULL ); printf( "It is now: %s", _ctime( &time_of_day, buf ) ); }
produces the output:
It is now: Fri Dec 25 15:58:42 1987
All (except Netware, DOS/PM)