C Reference function ctime()
Usage of ctime():
char * ctime ( const time_t * ptr_time );
Parameters:
Pointer ptr_time to a time_t object that contains a calendar time.
Return Value:
The function returns a C string containing the date and time information.
The string is followed by a new-line character (‘\n’) Converts the time_t object pointed by timer to a C string containing a human-readable version of the corresponding local time and date.
The functions ctime and asctime share the array which holds this string. If either one of these functions is called, the content of the array is overwritten.
Explanation:
The string that is returned will have the following format:
Www Mmm dd hh:mm:ss yyyy
Www = which day of the week.
Mmm = month in letters.
dd = the day of the month.
hh:mm:ss = the time in hour, minutes, seconds.
yyyy = the year.
Source code example of ctime():
#include <stdio.h>
#include <time.h>
int main ()
{
time_t time_raw_format;
time ( &time_raw_format );
printf ( "The current local time: %s", ctime(&time_raw_format));
return 0;
}
Output example of the program above:
The current local time: Fri Jan 11 12:09:51 2008
Note: this function is equivalent to: asctime(localtime(timer)).