ctime | function |
char * ctime ( const time_t * timer ); |
<ctime> |
Convert time_t value to string
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 returned string has the following format:
Www Mmm dd hh:mm:ss yyyy
Where Www is the weekday, Mmm the month in letters, dd the day of the month, hh:mm:ss the time, and yyyy the year.
The string is followed by a new-line character ('\n') and the terminating null-character.
This function is equivalent to: asctime(localtime(timer)).
Parameters
- timer
- Pointer to a time_t object that contains a calendar time.
Return Value
A C string containing the date and time information in a human-readable format.The array which holds this string is statically allocated and shared by both the ctime and asctime functions. Each time either one of these functions is called the content of this array is overwritten.
Example
/* ctime example */ #include <stdio.h> #include <time.h> int main () { time_t rawtime; time ( &rawtime ); printf ( "The current local time is: %s", ctime (&rawtime) ); return 0; } |
Output:
The current local time is: Sat May 20 15:21:51 2000 |
See also
asctime | Convert tm structure to string (function) |
gmtime | Convert time_t to tm as UTC time (function) |
localtime | Convert time_t to tm as local time (function) |
time | Get current time (function) |