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

Definition  

#include <time.h>

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

gmtime and gmtime64 interpret the time specification to which sec_p points as the number of seconds which have passed since the reference date (epoch).
The functions calculate the date and time from this and store the result in a structure of the type tm.
If the POSIX "linkage option" library has been linked with preference, the result is stored in UTC (Universal Time Coordinated) format, otherwise as local time.
Negative values are interpreted as seconds before the reference date. The earliest displayable date with gmtime is 12/13/1901 20:45:52 local time and 01/01/1900 00:00:00 with gmtime64.

The latest date which can be displayed with gmtime is 01/19/2038 03:14:07 and 3/18/4317 02:44:48 with gmtime64.

Warning

If the POSIX "linkage option" library has not been linked with preference, it is not possible to get the result in UTC format.
In this case gmtime and gmtime64 correspond to the localtime and localtime64 functions, each supplying the local time.

Return val.

Pointer to the calculated structure. gmtime and gmtime64 store the result in a structure declared in <time.h> as follows:


struct tm
{
  int   tm_sec;        /* seconds (0-59) */
  int   tm_min;        /* minutes (0-59) */
  int   tm_hour;       /* hours (0-23) */
  int   tm_mday;       /* day of the month (1-31) */
  int   tm_mon;        /* month from the start of the year (0-11) */
  int   tm_year;       /* years since 1900 */
  int   tm_wday;       /* weekday (0-6, 0=Sunday) */
  int   tm_yday;       /* days since January 1 (0-365) */
  int   tm_isdst;      /* daylight saving time flag */
};

NULL

In the event of an 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.

Example

#include <time.h>
#include <stdio.h>
struct tm *t;
char *s;
time_t clk;
int main(void)
{
  clk = time((time_t *)0);
  t = gmtime(&clk);
  printf("Year: %d\n", t->tm_year + 1900);
  printf("Time in hours: %d\n", t->tm_hour);
  printf("Day of the year: %d\n", t->tm_yday);
  s = asctime(t);
  printf("%s", s);
  return 0;
}

See also

asctime, ctime, ctime64, localtime, localtime6