This documentation is archived and is not being maintained.

ctime, _ctime64, _wctime, _wctime64

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

char *ctime( 
   const time_t *timer 
char *_ctime64( 
   const __time64_t *timer )
wchar_t *_wctime( 
   const time_t *timer 
wchar_t *_wctime64( 
   const __time64_t *timer 


Pointer to stored time.

Return Value

A pointer to the character string result. NULL will be returned if:

  • time represents a date before midnight, January 1, 1970, UTC.
  • If you use ctime or _wctime and time represents a date after 19:14:07 January 18, 2038.
  • If you use _ctime64 or _wctime64 and time represents a date after 23:59:59, December 31, 3000, UTC.


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 return value string 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 and _wctime64 are the wide-character version of ctime and _ctime64; returning a pointer to wide-character string. Otherwise, _ctime64, _wctime, and _wctime64 behave identically to ctime.

Generic-Text Routine Mappings

TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_tctime ctime ctime _wctime
_tctime64 _ctime64 _ctime64 _wctime64


Routine Required header Compatibility
ctime <time.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
_ctime64 <time.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_wctime <time.h> or <wchar.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_wctime64 <time.h> or <wchar.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// crt_ctime64.c
/* This program gets the current
 * time in _time64_t form, then uses ctime to
 * display the time in string form.

#include <time.h>
#include <stdio.h>

int main( void )
   __time64_t ltime;

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

Sample Output

The time is Wed Feb 13 16:04:43 2002

See Also

Time Management Routines | asctime | _ftime | gmtime | localtime | time | Run-Time Routines and .NET Framework Equivalents