Converts given time since epoch (a
time_tvalue pointed to by
timer) into calendar time, expressed in local time, in the
struct tm
format. The result is stored in static storage and a pointer to that static storage is returned.
2) Same as (1), except that the function uses user-provided storage buf for the result.
3)Same as
(1), except that the function uses user-provided storage
buffor the result and that the following errors are detected at runtime and call the currently installed
constraint handlerfunction:
localtime_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>.
pointer to a static internal
tmobject on success, or null pointer otherwise. The structure may be shared between
gmtime,
localtime
, and
ctimeand may be overwritten on each invocation.
2,3) copy of the buf pointer, or null pointer on error (which may be a runtime constraint violation or a failure to convert the specified time to local calendar time).
[edit] NotesThe function localtime
may not be thread-safe. The Microsoft CRT implementation is thread-safe.
POSIX requires that localtime
and localtime_r
set errno to EOVERFLOW if it fails because the argument is too large.
POSIX specifies that the timezone information is determined by localtime
and localtime_r
as if by calling tzset
, which reads the environment variable TZ.
The implementation of localtime_s
in Microsoft CRT is incompatible with the C standard since it has reversed parameter order and returns errno_t.
#define __STDC_WANT_LIB_EXT1__ 1 #define _XOPEN_SOURCE // for putenv #include <stdio.h> #include <stdlib.h> // for putenv #include <time.h> int main(void) { time_t t = time(NULL); printf("UTC: %s", asctime(gmtime(&t))); printf("local: %s", asctime(localtime(&t))); // POSIX-specific putenv("TZ=Asia/Singapore"); printf("Singapore: %s", asctime(localtime(&t))); #ifdef __STDC_LIB_EXT1__ struct tm buf; char str[26]; asctime_s(str, sizeof str, gmtime_s(&t, &buf)); printf("UTC: %s", str); asctime_s(str, sizeof str, localtime_s(&t, &buf)); printf("local: %s", str); #endif }
Possible output:
UTC: Fri Sep 15 14:22:05 2017 local: Fri Sep 15 14:22:05 2017 Singapore: Fri Sep 15 22:22:05 2017 UTC: Fri Sep 15 14:22:05 2017 local: Fri Sep 15 14:22:05 2017[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