Format
#include <time.h> struct tm *gmtime(const time_t *time);
Language Level: ANSI, POSIX, XPG4
The gmtime function breaks down the time value and
stores it in a tm structure, defined in <time.h>.
The structure pointed to by the return value reflects Universal Coordinate Time (UTC), not local time. The value time is usually obtained from a call to time.
The fields of the tm structure include:
| tm_sec | Seconds (0-61) |
| tm_min | Minutes (0-59) |
| tm_hour | Hours (0-23) |
| tm_mday | Day of month (1-31) |
| tm_mon | Month (0-11; January = 0) |
| tm_year | Year (current year minus 1900) |
| tm_wday | Day of week (0-6; Sunday = 0) |
| tm_yday | Day of year (0-365; January 1 = 0) |
| tm_isdst | Zero if Daylight Saving Time is not in effect; positive if Daylight Saving Time is in effect; negative if the information is not available. |
Return Value
gmtime returns a pointer to the resulting tm structure.
On both OS/2 and Windows, it returns NULL if UTC is not available.
Notes:
On both OS/2 and Windows, the time and date functions begin at 00:00:00 Universal Coordinate Time, January 1, 1970, and do not have an upper limit.
Example
This example uses gmtime to adjust a time_t
representation to an Universal Coordinate Time character string,
and then converts it to a printable string using asctime.
#include <stdio.h> #include <time.h>
int main(void)
{
time_t ltime;
time(<ime);
printf ("Universal Coordinate Time is %s\n",
asctime(gmtime(<ime)));
return 0;
/********************************************************
The output should be similar to:
Universal Coordinate Time is Mon Sep 16 21:44 1995 ********************************************************/ }
![]()
asctime -- Convert Time to Character
String
ctime -- Convert Time to Character String
gmtime -- Convert Time
localtime -- Convert Time
mktime -- Convert Local Time
setlocale -- Set Locale
time -- Determine Current Time
<time.h>