Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <time.h>
char *asctime(const struct tm *timeptr);
#define _LARGE_TIME_API
#include <time.h>
char asctime64(const struct tm *timeptr);
Converts time stored as a structure, pointed to by timeptr, to a character string. The timeptr value can be obtained from a call to gmtime() or localtime(). Both functions return a pointer to a tm structure defined in time.h.
"%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"
The
following is an example of the string returned: Fri Jun 16 02:03:55 2001\n\0
The function asctime64() will behave exactly like asctime() except it will support a structured date beyond 03:14:07 UTC on January 19, 2038 with a limit of 23:59:59 UTC on December 31, 9999.
If successful, asctime() returns a pointer to the resulting character string.
If the function is unsuccessful, it returns NULL.
⁄* CELEBA06
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);
⁄* Break it down & store it in the structure tm *⁄
newtime = localtime(<ime);
⁄* Print the local time as a string *⁄
printf("The current date and time are %s",
asctime(newtime));
}
The current date and time are Fri Jun 16 13:29:51 2001