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
DDD | Day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat) |
MMM | Month of the year (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec) |
dd | Day of the month (1,…,31) |
hh | Hour (0,…,23) |
mm | Minute (0,…,59) |
ss | Second (0,…,59) |
YYYY | Year |
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; }