Home >>C Time Library Function >C asctime() function
The C time asctime() function is used to return a pointer to the string which contains the information of the day and time of the structure struct timeptr. It takes a pointer to tm object as its parameter and returns a text representation for a given calendar time. This function is defined in header file.
Syntax:
char *asctime(const struct tm *timeptr)
Timeptr: It is a pointer to tm structure that contains a calendar time broken down into its components.
Here is an example of asctime() function:
#include <stdio.h>
#include <string.h>
#include <time.h>
int main ()
{
struct tm t;
t.tm_sec = 10;
t.tm_min = 10;
t.tm_hour = 6;
t.tm_mday = 25;
t.tm_mon = 2;
t.tm_year = 89;
t.tm_wday = 6;
puts(asctime(&t));
return(0);
}
Example-2
#include <stdio.h>
#include <string.h>
#include <time.h>
int main ()
{
struct tm t;
t.tm_sec = 32;
t.tm_min = 23;
t.tm_hour = 4;
t.tm_mday = 12;
t.tm_mon = 4;
t.tm_year = 20;
t.tm_wday = 5;
puts(asctime(&t));
return(0);
}