CKTIS / C
localtime — C23 time function
`localtime(timer)` from `<time.h>` converts the designated `time_t` to local broken-down calendar time and returns a pointer to `struct tm`; it applies the environment’s time-zone and daylight-saving rules. It may return null on failure.
Version: C23
Syntax
struct tm *localtime(const time_t *timer);localtime(timer) from <time.h> converts the designated time_t to local broken-down calendar time and returns a pointer to struct tm; it applies the environment’s time-zone and daylight-saving rules. It may return null on failure.
The example passes a zero time_t to localtime and checks the pointer plus month, day, hour, minute, and second ranges. It prints 1 in the execution environment without assuming a particular time zone.
The result points to a static object that a later localtime, gmtime, or ctime may overwrite; copy the struct tm immediately. The function is not required to be safe under concurrent calls. tm_isdst may be positive, zero, or negative, and ambiguous or nonexistent local times around DST transitions require care when converting back with mktime.
Examples
#include <stdio.h>
#include <time.h>
int main(void){time_t raw=0;struct tm *v=localtime(&raw);int ok=v&&v->tm_mon>=0&&v->tm_mon<=11&&v->tm_mday>=1&&v->tm_mday<=31&&v->tm_hour>=0&&v->tm_hour<=23&&v->tm_min>=0&&v->tm_min<=59&&v->tm_sec>=0&&v->tm_sec<=60;printf("%d\n",ok);return 0;}
Result
1
The example passes a zero `time_t` to `localtime` and checks the pointer plus month, day, hour, minute, and second ranges. It prints `1` in the execution environment without assuming a particular time zone.