| Functions | ||||
| Time manipulation | ||||
(C11) | ||||
(C23) | ||||
| Format conversions | ||||
(deprecated in C23)(C11) | ||||
ctimectime_s (deprecated in C23)(C11) | ||||
(C95) | ||||
(C23)(C11) | ||||
(C23)(C11) | ||||
| Constants | ||||
| Types | ||||
(C11) |
Defined in header <time.h> | ||
| (1) | ||
char* ctime(consttime_t* timer); | (until C23) | |
[[deprecated]]char* ctime(consttime_t* timer); | (since C23) | |
errno_t ctime_s(char*buf, rsize_t bufsz,consttime_t* timer); | (2) | (since C11) |
buf ortimer is a null pointerbufsz is less than26 or greater thanRSIZE_MAXctime_s is only guaranteed to be available if__STDC_LIB_EXT1__ is defined by the implementation and if the user defines__STDC_WANT_LIB_EXT1__ to the integer constant1 before including<time.h>.The resulting string has the following format:
Www Mmm dd hh:mm:ss yyyy\n
Www - the day of the week (one ofMon,Tue,Wed,Thu,Fri,Sat,Sun).Mmm - the month (one ofJan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec).dd - the day of the monthhh - hoursmm - minutesss - secondsyyyy - yearsThe function does not support localization.
Contents |
| timer | - | pointer to atime_t object specifying the time to print |
| buf | - | pointer to the first element of a char array of size at leastbufsz |
| bufsz | - | max number of bytes to output, typically the size of the buffer pointed to bybuf |
ctime, and may be overwritten on each invocation of any of those functions.buf), or non-zero on failure (in which case, the terminating null character is always written tobuf[0] unlessbuf is a null pointer orbufsz is zero or greater thanRSIZE_MAX.ctime returns a pointer to static data and is not thread-safe. In addition, it modifies the statictm object which may be shared withgmtime andlocaltime. POSIX marks this function obsolete and recommendsstrftime instead. The C standard also recommendsstrftime instead ofctime andctime_s becausestrftime is more flexible and locale-sensitive.
The behavior ofctime is undefined for the values oftime_t that result in the string longer than 25 characters (e.g. year 10000).
Possible output:
Tue May 26 21:51:03 2015Tue May 26 21:51:03 2015
(deprecated in C23)(C11) | converts atm object to a textual representation (function)[edit] |
| converts atm object to custom textual representation (function)[edit] | |
C++ documentation forctime | |