Name

asctime

Synopsis

Converts a date and time structure to string form

#include <time.h>
char *asctime( struct tm *systime );

The single argument of the asctime() function is a pointer to a structure of type struct tm, in which a date and time is represented by elements for the year, month, day, hour, and so on. The structure is described under mktime() in this chapter. The asctime() function returns a pointer to a string of 26 bytes containing the date and time in a timestamp format:

"Wed Apr 13 07:23:20 2005\n"

The day of the week and the month are abbreviated with the first three letters of their English names, with no period. If the day of the month is a single digit, an additional space fills the place of its tens digit. If the hour is less than ten, it is represented with a leading zero.

Example

time_t now;
time( &now );                 /* Get the time (seconds since 1/1/70) */
printf( "Date: %.24s GMT\n",asctime( gmtime( &now ) ));

Typical output:

Date: Sun Aug 28 14:22:05 2005 GMT

See Also

localtime(), gmtime(), ctime(), difftime(), mktime(), strftime(), time(). The localtime() and gmtime() functions are the most common ways of filling in the values in the tm structure. The function call ctime(&seconds) is equivalent to the call asctime(localtime(&seconds))

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.