Converts a tm time structure to a character string.
#include <time.h>
char *asctime( const struct tm *timeptr );
timeptr | Time/date structure |
The asctime function converts a time stored as a structure to a character string. The timeptr value is usually obtained from a call to gmtime or localtime, both of which return a pointer to a tm structure, defined in TIME.H. (See gmtime for a complete description of the tm structure fields.)
The tm structure contains the following elements:
Element | Description |
int tm_sec | Seconds after the minute (0–59) |
int tm_min | Minutes after the hour (0–59) |
int tm_hour | Hours since midnight (0–23) |
int tm_mday | Day of the month (0–31) |
int tm_mon | Months since January (0–11) |
int tm_year | Years since 1900 |
int tm_wday | Days since Sunday (0–6) |
int tm_yday | Days since January 1 (0–365) |
int tm_isdst | Daylight-saving-time flag |
The string result produced by asctime contains exactly 26 characters and has the form of the following example:
Wed Jan 02 02:03:55 1980\n\0
A 24-hour clock is used. All fields have a constant width. The newline character (\n) and the null character ('\0') occupy the last two positions of the string. The asctime function uses a single statically allocated buffer to hold the return string. Each call to this routine destroys the result of the previous call.
The asctime function returns a pointer to the character string result. There is no error return.
Standards:ANSI, UNIX
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
ctime, _ftime, gmtime, localtime, time, _tzset
/* ASCTIME.C: This program places the system time in the long integer aclock,
* translates it into the structure newtime and then converts it to
* string form for output, using the asctime function.
*/
#include <time.h>
#include <stdio.h>
struct tm *newtime;
time_t aclock;
void main( void )
{
time( &aclock ); /* Get time in seconds */
newtime = localtime( &aclock ); /* Convert time to struct tm form */
/* Print local time as a string */
printf( "The current date and time are: %s\n", asctime( newtime ) );
}
The current date and time are: Tue Jun 15 06:57:59 1999