Converts time to a string.
char* asctime (const struct tm * timeptr);
This function has the following parameter.
C-string containing the date and time in a human-readable format.
#include <time.h>
#include <stdio.h>
int main(void)
{
struct tm tm = *localtime(&(time_t){time(NULL)});
printf("%s", asctime(&tm));
}
The code above generates the following result.
#include <stdio.h> /* printf */
#include <time.h> /* time_t, struct tm, time, localtime, asctime */
/* w w w. j av a2 s.c o m*/
int main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "The current date/time is: %s", asctime (timeinfo) );
return 0;
}
The code above generates the following result.