A pointer to a `struct tm`, which represents a broken-down calendar time. The structure contains fields such as year, month, day, hour, minute, and second for representing human-readable time.
Read about return values of localtime_r function .
1st Parameter Type : const time_t *
A pointer to a constant `time_t` object, representing time as the number of seconds since the epoch (00:00:00 UTC, January 1, 1970). The data it points to cannot be modified.
1st Parameter
Pointer to a `time_t` object representing the time in seconds since the epoch.
2nd Parameter Type : struct tm *
A pointer to a `struct tm`, which represents a broken-down calendar time. The structure contains fields such as year, month, day, hour, minute, and second for representing human-readable time.
2nd Parameter
Pointer to a user-supplied `struct tm` where the result will be stored.
Read more about parameters of localtime_r in parameters section
The localtime_rfunction in C language Thread-safe version of localtime.
The localtime_r function converts the calendar time pointed to by timer into a broken-down time representation, expressed as local time. The result is stored in the structure pointed to by result. This function is the reentrant version of localtime, making it safe for use in multi-threaded programs.
The localtime_rfunction takes 2
parameters:
•
const time_t * `timer`: Pointer to a `time_t` object representing the time in seconds since the epoch.
•
struct tm * `result`: Pointer to a user-supplied `struct tm` where the result will be stored.
A thread-safe version of `localtime`. Converts the given time value pointed to by `timer` into a broken-down local time representation and stores the result in the `struct tm` pointed to by `result`. Returns the same pointer as `result` on success, or `NULL` on failure.
The localtime_r function return value :
Returns a pointer to the resulting struct tm (which is the same as the result parameter), or NULL if the time cannot be represented
Output
This example demonstrates basic usage of localtime_r to get the current local time in a thread-safe manner.