asctime function returns time in string
Syntax
C asctime function has the following syntax.
char *asctime(const struct tm *ptr);
Header
C asctime function
is from header file time.h
.
Description
C asctime function returns a string for tm in the following form:
day month date hours:minutes:seconds year\n\0
For example:
Fri Apr 15 12:05:34 2005
Example
Use C asctime function to get current time in string type.
#include <time.h>
#include <stdio.h>
// w ww . j a v a 2s . c o m
int main(void)
{
struct tm *ptr;
time_t lt;
lt = time(NULL);
ptr = localtime(<);
printf(asctime(ptr));
return 0;
}
The code above generates the following result.