asctime, _wasctime
Collapse the table of content
Expand the table of content

asctime, _wasctime

Convert a tm time structure to a character string. More secure versions of these functions are available; see asctime_s, _wasctime_s.

char *asctime( 
   const struct tm *timeptr 
wchar_t *_wasctime( 
   const struct tm *timeptr 


Time/date structure.

asctime returns a pointer to the character string result; _wasctime returns a pointer to the wide-character string result. There is no error return value.

More secure versions of these functions are available; see asctime_s, _wasctime_s.

The asctime function converts a time stored as a structure to a character string. The timeptr value is usually obtained from a call to gmtime or localtime, which both return a pointer to a tm structure, defined in TIME.H.

timeptr member



Hours since midnight (0–23)


Positive if daylight saving time is in effect; 0 if daylight saving time is not in effect; negative if status of daylight saving time is unknown. The C run-time library assumes the United States' rules for implementing the calculation of Daylight Saving Time (DST).


Day of month (1–31)


Minutes after hour (0–59)


Month (0–11; January = 0)


Seconds after minute (0–59)


Day of week (0–6; Sunday = 0)


Day of year (0–365; January 1 = 0)


Year (current year minus 1900)

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

The string result produced by asctime 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 and the null character occupy the last two positions of the string. asctime uses a single, statically allocated buffer to hold the return string. Each call to this function destroys the result of the previous call.

_wasctime is a wide-character version of asctime. _wasctime and asctime behave identically otherwise.

These functions validate their parameters. If timeptr is a null pointer, or if it contains out-of-range values, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, the function returns NULL and sets errno to EINVAL.

Generic-Text Routine Mapping

TCHAR.H routine

_UNICODE & _MBCS not defined

_MBCS defined

_UNICODE defined






Required header




<time.h> or <wchar.h>

This program places the system time in the long integer aclock, translates it into the structure newtime and then converts it to string form for output, using the asctime function.

// crt_asctime.c
// compile with: /W3

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

int main( void )
    struct tm   *newTime;
    time_t      szClock;

    // Get time in seconds
    time( &szClock );

    // Convert time to struct tm form 
    newTime = localtime( &szClock );

    // Print local time as a string.
    printf_s( "Current date and time: %s", asctime( newTime ) ); // C4996
    // Note: asctime is deprecated; consider using asctime_s instead
Current date and time: Sun Feb 03 11:38:58 2002
© 2015 Microsoft