Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

localtime, localtime64 - convert date and time to local time

&pagelevel(4)&pagelevel

Syntax

#include <time.h>

struct tm *localtime(const time_t *clock);
struct tm *localtime64(const time64_t *clock);

Description

Description  The functions localtime() and localtime64() interpret the time specification of the value to which clock points as the number of seconds that have elapsed since 1.1.1970 00:00:00 hrs UTC (epoch). Such a value is returned for example by the functions time() and time64(). gmtime() and gmtime64() calculate from this the date and time in UTC and store it in a type tm structure. Negative values are interpreted as seconds before the epoch. The following points in time are considered invalid:

  • with localtime() points in time before 13.12.1901 20:45:52 hrs UTC and after 19.01.2038 03:14:07 Uhr UTC
  • with localtime64() points in time before 1.1.1900 00:00:00 hrs UTC and after 31.12.9999 23:59:59 hrs UTC.

The local time zone information is used as if the tzset function has been called.

The localtime() function corrects for the timezone and any seasonal time adjustments.

The declarations of all functions, external values, and of the tm structure are contained in the header time.h. The tm structure is defined as follows:

struct      tm {
    int     tm_sec;         /* Seconds - [0, 61] for skipped seconds */
    int     tm_min;         /* Minutes - [0, 59] */
    int     tm_hour;        /* Hours - [0, 23] */
    int     tm_mday;        /* Day of month - [1, 31] */
    int     tm_mon;         /* Months - [0, 11] */
    int     tm_year;        /* Years since 1900 */
    int     tm_wday;        /* Days since Sunday - [0, 6] */
    int     tm_yday;        /* Days since January - [0, 365] */
    int     tm_isdst;       /* Option for daylight saving time */
}; 

tm_isdst is positive if daylight saving time is set, null if daylight saving time is not set, and negative if the information is not available.

localtime() is not thread-safe. Use the reentrant function localtime_r() when needed.

BS2000 localtime() interprets the time specification of type time_t as the number of seconds that have elapsed since January 1, 1970, 00:00:00 local time. From this number, localtime() calculates the date and time and stores the result in a structure of type tm.

In this implementation, localtime() is equivalent to gmtime(); both functions return the local time. (End)

Return val.

Pointer to the tm structure



if successful.

 

EOVERFLOW

In case of an error. errno is set to indicate the error.

Notes

The asctime(), ctime(), ctime64(), gmtime(), gmtime64(), localtime() and localtime64() functions write their result into the same internal C data area. This means that each of these function calls overwrites the previous result of any of the other functions.

localtime() does not support local date and time formats; to ensure maximum portability, strftime() should be used instead.

localtime() writes its result to an internal C data area that is overwritten with each call.

Furthermore, localtime() and gmtime() use the same data area, which means that if they are called in succession, the result of the first call will be overwritten.

See also

altzone, ctime(), daylight, gmtime(), localtime_r(), strftime(), tzname, tzset(), time.h.