C Library Function - ctime()
Description
The C library function char *ctime(const time_t *timer) returns a string representing the local time based on the argument timer.
The returned string has the following format: Www Mmm dd hh:mm:ss yyyy where Www is the weekday, Mmm is the month in letters, dd is the day of the month, hh:mm:ss is the time, and yyyy is the year.
Declaration
Here is the declaration for the ctime() function.
char *ctime(const time_t *timer)
Parameters
- timer -- This is a pointer to a time_t object that contains a calendar time.
Return Value
The function returns a C string containing the date and time information in a readable format.
Example
The following example demonstrates the use of the ctime() function.
#include <stdio.h>
#include <time.h>
int main ()
{
time_t curtime;
time(&curtime);
printf("Current time = %s", ctime(&curtime));
return(0);
}
Let's compile and run the above program, which will produce the following result:
Current time = Mon Aug 13 08:23:14 2012