ctime, _wctime

Convert a time value to a string and adjust for local time zone settings.

char *ctime( const time_t *timer );

wchar_t *_wctime( const time_t *timer );

Routine Required Header Compatibility
ctime <time.h> ANSI, Win 95, Win NT
_wctime <time.h> or <wchar.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Each of these functions returns a pointer to the character string result. If time represents a date before midnight, January 1, 1970, UTC, the function returns NULL.

Parameter

timer

Pointer to stored time

Remarks

The ctime function converts a time value stored as a time_t structure into 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), January 1, 1970, coordinated universal time (UTC). The string result produced by ctime contains exactly 26 characters and has the form:

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.

The converted character string is also adjusted according to the local time zone settings. See the time, _ftime, and localtime functions for information on configuring the local time and the _tzset function for details about defining the time zone environment and global variables.

A call to ctime modifies the single statically allocated buffer used by the gmtime and localtime functions. Each call to one of these routines destroys the result of the previous call. ctime 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.

_wctime is a wide-character version of ctime; _wctime returns a pointer to a wide-character string. _wctime and ctime behave identically otherwise.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tctime ctime ctime _wctime

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 Fri Apr 29 12:25:12 1994

Time Management Routines

See Also   asctime, _ftime, gmtime, localtime, time