Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

gmtime, gmtime64 - convert date and time to UTC

&pagelevel(4)&pagelevel

Syntax

#include <time.h>

struct tm *gmtime(const time_t *clock);
struct tm *gmtime64(const time64_t *clock);

Description

The functions gmtime() and gmtime64() 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 gmtime() points in time before 13.12.1901 20:45:52 hrs UTC and after 19.01.2038 03:14:07 Uhr UTC
  • with gmtime64() points in time before 1.1.1900 00:00:00 hrs UTC and after 31.12.9999 23:59:59 hrs UTC.

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 (always 0) */
}; 

BS2000
gmtime() 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, gmtime() calculates the date and time and stores the result in a structure of type tm. In this implementation, gmtime() is equivalent to localtime(); both functions return the local time. (End)

gmtime() is not thread-safe. Use the reentrant function gmtime_r() when needed.

Return val.

Pointer to a structure of type struct tm


if successful.

EOVEFLOW

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.

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

gmtime() writes its result to an internal C data area that is overwritten with each call.
Furthermore, gmtime() and localtime() 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, localtime(), strftime(), tzname, tzset().