asctime(), _asctime()

convert time information to a string


#include <time.h>

char *asctime( const struct tm *timeptr );
char *_asctime( const struct tm *timeptr, 
                char *buf );


The asctime() functions convert the time information in the structure pointed to by timeptr 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 newline character '\n' and the null character '\0' occupy the last two positions of the string.

The ANSI function asctime() places the resulting string in a static buffer that is re-used each time asctime() or ctime is called.

The non-ANSI function _asctime() places the resulting string in the buffer pointed to by buf.


A pointer to the character string result.


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

void main()
    struct tm  time_of_day;
    time_t     ltime;
    char       buf[26];

    time( &ltime );
    _localtime( &ltime, &time_of_day );
    printf( "Date and time is: %s\n",
            _asctime( &time_of_day, buf ) );

produces the output:

Date and time is: Sat Mar 21 15:58:27 1987


asctime() is ANSI; _asctime() is WATCOM.

Interrupt handler No
Signal handler No
Thread Yes

See also:

clock(), ctime(), difftime(), gmtime(), localtime(), mktime(), strftime(), time(), tzset()

The tm structure is described in the section on <time.h> in the Header Files chapter.