Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <time.h>
char *ctime(const time_t *timer);
#define _LARGE_TIME_API
#include <time.h>
char *ctime64 (const time64_t *timer);
Converts the calendar time pointed to by timer to local time in the form of a character string. A value for timer is usually obtained by a call to the time() function.
The ctime() function is equivalent to the function call: asctime(localtime(timer))
The function ctime64() will behave exactly like ctime() except it will convert a time64_t value pointing to a calendar time beyond 03:14:07 UTC on January 19, 2038 with a limit of 23:59:59 UTC on December 31, 9999.
"%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"
For example: Mon Jul 16 02:03:55 1987\n\0
If an error occurs, ctime() returns no value.
When neither TZ nor _TZ is defined, the current locale is interrogated for time zone information. If neither TZ nor _TZ is defined and LC_TOD time zone information is not present in the current locale, a default value is applied to local time. POSIX programs simply default to Coordinated Universal Time (UTC), while non-POSIX programs establish an offset from UTC based on the setting of the system clock.
For more information about customizing a time zone to work with local time, see “Customizing a time zone” in z/OS XL C/C++ Programming Guide.
⁄* CELEBC33
This example polls the system clock by using the library
function &ttime..
It then prints a message giving the current date and time.
*⁄
#include <time.h>
#include <stdio.h>
int main(void)
{
time_t ltime;
time(<ime);
printf("the time is %s", ctime(<ime));
}
the time is Fri Jun 16 16:03:38 2001