| Functions | ||||
| Time manipulation | ||||
(C11) | ||||
(C23) | ||||
| Format conversions | ||||
(deprecated in C23)(C11) | ||||
(deprecated in C23)(C11) | ||||
(C95) | ||||
(C23)(C11) | ||||
localtimelocaltime_rlocaltime_s (C23)(C11) | ||||
| Constants | ||||
| Types | ||||
(C11) |
Defined in header <time.h> | ||
| (1) | ||
| (2) | (since C23) | |
| (3) | (since C11) | |
struct tm format. The result is stored in static storage and a pointer to that static storage is returned.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 constant1 before including<time.h>.Contents |
| timer | - | pointer to atime_t object to convert |
| buf | - | pointer to astructtm object to store the result |
localtime, andctime and may be overwritten on each invocation.The functionlocaltime may not be thread-safe. TheMicrosoft CRT implementation is thread-safe.
POSIX requires thatlocaltime andlocaltime_r seterrno toEOVERFLOW if it fails because the argument is too large.
POSIX specifies that the timezone information is determined bylocaltime andlocaltime_r as if by callingtzset, which reads the environment variableTZ.
The implementation oflocaltime_s inMicrosoft CRT is incompatible with the C standard since it has reversed parameter order and returnserrno_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__structtm 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 2017local: Fri Sep 15 14:22:05 2017Singapore: Fri Sep 15 22:22:05 2017UTC: Fri Sep 15 14:22:05 2017local: Fri Sep 15 14:22:05 2017
(C23)(C11) | converts time since epoch to calendar time expressed as Coordinated Universal Time (UTC) (function)[edit] |
C++ documentation forlocaltime | |