asctime Function

Converts the time structure to a character string.




char *asctime(const struct tm *tptr);


time/date structure

Return Value

Returns a pointer to a character string of the following format:

DDD MMM dd hh:mm:ss YYYY

DDD is day of the week

MMM is month of the year

dd is day of the month

hh is hour

mm is minute

ss is second

YYYY is year


See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

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

volatile int i;

int main(void)
  struct tm when;
  time_t whattime;

  when.tm_sec = 30;
  when.tm_min = 30;
  when.tm_hour = 2;
  when.tm_mday = 1;
  when.tm_mon = 1;
  when.tm_year = 103;

  whattime = mktime(&when);
  printf("Day and time is %s\n", asctime(&when));

Example Output

Day and time is Sat Feb  1 02:30:30 2003