Format
#include <time.h> char *asctime(const struct tm *time);
Language Level: ANSI
Threadsafe: No. Use asctime_r() instead.
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 the gmtime() function or the localtime() function; either returns a pointer to a tm structure defined in <time.h>.
The string result that asctime() produces contains exactly 26 characters and has the format:
"%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"
The following are examples of the string returned:
Sat Jul 16 02:03:55 1994\n\0 or Sat Jul 16 2:03:55 1994\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.
Return Value
The asctime() function returns a pointer to the resulting character string. If the function is unsuccessful, it returns NULL.
Example that uses asctime()
This example polls the system clock and prints a message that gives 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)); } /**************** Output should be similar to: ****************** The current date and time are Fri Sep 16 13:29:51 1994 */
Related Information
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.