gmtime
Go Up to time.h Index
Header File
time.h
Category
Time and Date Routines
Prototype
struct tm *gmtime(const time_t *timer);
Description
Converts date and time to Greenwich mean time (GMT).
gmtime accepts the address of a value returned by time and returns a pointer to the structure of type tm containing the time elements. gmtime converts directly to GMT.
The global long variable _timezone should be set to the difference in seconds between GMT and local standard time (in PST _timezone is 8 x 60 x 60). The global variable _daylight should be set to nonzero only if the standard U.S. daylight saving time conversion should be applied.
This is the tm structure declaration from the time.h header file:
struct tm { int tm_sec; /* Seconds */ int tm_min; /* Minutes */ int tm_hour; /* Hour (0 - 23) */ int tm_mday; /* Day of month (1 - 31) */ int tm_mon; /* Month (0 - 11) */ int tm_year; /* Year (calendar year minus 1900) */ int tm_wday; /* Weekday (0 - 6; Sunday is 0) */ int tm_yday; /* Day of year (0 -365) */ int tm_isdst; /* Nonzero if daylight saving time is in effect. */ };
These quantities give the time on a 24-hour clock, day of month (1 to 31), month (0 to 11), weekday (Sunday equals 0), year - 1900, day of year (0 to 365), and a flag that is nonzero if daylight saving time is in effect.
Return Value
gmtime returns a pointer to the structure containing the time elements. This structure is a static that is overwritten with each call.
Example
#include <stdio.h> #include <stdlib.h> #include <time.h> /* Pacific Standard Time & Daylight Savings */ char *tzstr = "TZ=PST8PDT"; int main(void) { time_t t; struct tm *gmt, *area; putenv(tzstr); tzset(); t = time(NULL); area = localtime(&t); printf("Local time is: %s", asctime(area)); gmt = gmtime(&t); printf("GMT is: %s", asctime(gmt)); return 0; }
Portability
POSIX | Win32 | ANSI C | ANSI C++ |
---|---|---|---|
+ |
+ |
+ |
+ |