2.15.2 asctime

Declaration:

char *asctime(const struct tm *timeptr);

Returns a pointer to a string which represents the day and time of the structure timeptr. The string is in the following format:

DDD MMM dd hh:mm:ss YYYY

DDDDay of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat)
MMMMonth of the year (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
ddDay of the month (1,…,31)
hhHour (0,…,23)
mmMinute (0,…,59)
ssSecond (0,…,59)
YYYYYear

The string is terminated with a newline character and a null character. The string is always 26 characters long (including the terminating newline and null characters).

A pointer to the string is returned.

Example:

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

int main(void)
{
  time_t timer;

  timer=time(NULL);
  printf("The current time is %s.\n",asctime(localtime(&timer)));
  return 0;
}