Converts given time since epoch to a calendar local time and then to a textual representation, as if by calling
asctime(localtime(timer)) or asctime(localtime_r(timer, &(struct tm){0}))(since C23).
This function is deprecated and should not be used in new code.(since C23) 2)Same as
(1), except that the function is equivalent to
asctime_s(buf, bufsz, localtime_s(timer, &(struct tm){0})), and the following errors are detected at runtime and call the currently installed
constraint handlerfunction:
buf
or timer
is a null pointerbufsz
is less than 26 or greater than RSIZE_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 constant 1 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 of Mon
, Tue
, Wed
, Thu
, Fri
, Sat
, Sun
).Mmm
- the month (one of Jan
, 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.
[edit] Parameters timer - pointer to a time_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 by buf
[edit] Return value 1)
pointer to a static null-terminated character string holding the textual representation of date and time. The string may be shared between
asctimeand
ctime
, and may be overwritten on each invocation of any of those functions.
2) zero on success (in which case the string representation of time has been written out to the array pointed to by buf
), or non-zero on failure (in which case, the terminating null character is always written to buf[0] unless buf
is a null pointer or bufsz
is zero or greater than RSIZE_MAX.
ctime
returns a pointer to static data and is not thread-safe. In addition, it modifies the static tm object which may be shared with gmtime and localtime. POSIX marks this function obsolete and recommends strftime instead. The C standard also recommends strftime instead of ctime
and ctime_s
because strftime
is more flexible and locale-sensitive.
The behavior of ctime
is undefined for the values of time_t that result in the string longer than 25 characters (e.g. year 10000).
#define __STDC_WANT_LIB_EXT1__ 1 #include <time.h> #include <stdio.h> int main(void) { time_t result = time(NULL); printf("%s", ctime(&result)); #ifdef __STDC_LIB_EXT1__ char str[26]; ctime_s(str,sizeof str,&result); printf("%s", str); #endif }
Possible output:
Tue May 26 21:51:03 2015 Tue May 26 21:51:03 2015[edit] References
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4