ctime
char * ctime ( const time_t * timer ); | time.h |
cplusplus.com |
Convert time_t value to string.
Converts timer to a string containing time and date adjusted to local time zone in
readable format.
timer is an integer value of type time_t defined as long int
by default in most compilers, and usually
returned by a call to time function.
The returned string has the following format:
Www Mmm dd hh:mm:ss yyyywhere 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 a terminating null-character, conforming a total of 26 characters.
Parameters.
Return Value.
A pointer to the string containing the date and time information in readable format.
The string pointed is statically allocated and shared by ctime and
asctime functions. Each time one of these functions
is called the content of the string is overwritten.
ctime also uses internally the buffer used by gmtime
and localtime as return value, so a call to this function
will overwrite this.
Portability.
Defined in ANSI-C.
Example.
/* ctime example */
#include <stdio.h>
#include <time.h>
main ()
{
time_t rawtime;
time ( &rawtime );
printf ( "Current date and time are: %s", ctime (&rawtime) );
return 0;
}
Output:
Current date and time are: Sat May 20 16:05:33 2000
See also.
asctime,
gmtime,
localtime,
time