ctime

Description

Converts a time stored as a time_t value to a character string.

#include <time.h> Required only for function declarations  

char *ctime( const time_t *timer );

timer Pointer to stored time  

Remarks

The ctime function converts a time stored as a time_t value to a character string. The timer value is usually obtained from a call to time, which returns the number of seconds elapsed since midnight (00:00:00), December 31, 1899, Universal Coordinated Time.

The string result produced by ctime contains exactly 26 characters and has the form of the following example:

Wed Jan 02 02:03:55 1980\n\0

A 24-hour clock is used. All fields have a constant width. The newline character (\n) and the null character ('\0') occupy the last two positions of the string.

Calls to the ctime function modify the single statically allocated buffer used by the gmtime and the localtime functions. Each call to one of these routines destroys the result of the previous call. The ctime function also shares a static buffer with the asctime function. Thus, a call to ctime destroys the results of any previous call to asctime, localtime, or gmtime.

Return Value

The ctime function returns a pointer to the character string result. If time represents a date before midnight, December 31, 1899, Universal Coordinated Time, ctime returns NULL.

Compatibility

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

asctime, _ftime, gmtime, localtime, time

Example

/* CTIME.C: This program gets the current time in time_t form, then uses

* ctime to display the time in string form.

*/

#include <time.h>

#include <stdio.h>

void main( void )

{

time_t ltime;

time( &ltime );

printf( "The time is %s\n", ctime( &ltime ) );

}

Output

The time is Tue Jun 15 16:08:18 1999