Syntax
#include <time.h> char *asctime(const struct tm *time);Description
The asctime function converts time, stored as a structure pointed to by time, to a character string. You can obtain the time value from a call to gmtime or localtime; either returns a pointer to a tm structure defined in <time.h>. See gmtime for a description of the tm structure fields.
The string result that asctime produces contains exactly 26 characters and has the format:
"%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"See printf for a description of format specifications. The following are examples of the string returned:
Sat Jul 14 02:03:55 1995\n\0or
Sat Jul 14 2:03:55 1995\n\0
The asctime function uses a 24-hour-clock format. The days are abbreviated to: Sun, Mon, Tue, Wed, Thu, Fri, and Sat. The months are abbreviated to: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, and Dec. All fields have constant width. Dates with only one digit are preceded either with a zero or a blank space. The new-line character (\n) and the null character (\0) occupy the last two positions of the string.
The time and date functions begin at 00:00:00 Universal Time, January 1, 1970. Returns
The asctime function returns a pointer to the resulting character string. There is no error return value.
Note: asctime, ctime, and other time functions may use a common, statically allocated buffer to hold the return string. Each call to one of these functions may destroy the result of the previous call.
This example polls the system clock and prints a message giving the current time.
#include <time.h> #include <stdio.h> int main(void) { struct tm *newtime; time_t ltime; /* Get the time in seconds */ time(<ime); /* Convert it to the structure tm */ newtime = localtime(<ime); /* Print the local time as a string */ printf("The current date and time are %s", asctime(newtime)); return 0; /**************************************************************************** The output should be similar to : The current date and time are Fri Jun 28 13:51 1995 ****************************************************************************/ }Related Information