gmtime
Converts date and time to Greenwich mean time (GMT).
Defined in header <time.h>
Syntax
#include <time.h>
struct tm *gmtime(const time_t *timer);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ | ■ |
Remarks
gmtime accepts the address of a value returned by time and returns a
| pointer to the structure of type tm containing the broken-down | time. |
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 8x60x60). The global variable daylight should be set to nonzero only if the standard U.S. daylight saving time conversion should be applied.
The tm structure declaration from the time.h include file is
struct tm {
| int tm_sec; | /* Seconds */ |
| int tm_min; | /* Minutes */ |
| int tm_hour; | /* Hour (0 - 23) */ |
| int tra_mday; | /* Day of month (1-31) */ |
| int tm_mon; | /* Month (0 - 11) */ |
| int tm_year; | /* Year (calender year minus 1900)V |
| int tm_wday; | /* Weekday (0 - 6; Sunday is 0) */ |
| int tm_yday; | /* Day of year (0 -365) */ |
| int tm_isdst; }; 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. | /* Nonzero if daylight saving timeis in effect |
Return value
gmtime returns a pointer to the structure containing the broken-down time. This structure is a static that is overwritten with each call.
See also
Example
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
/* pacific standard & daylight savings time */
char *tzstr = "TZ=PST8PDT";
int main (void)
{
time_t t;
struct tm *gmt, *area;
putenv(tzstr) ;
tzset0 ;
t = time (NULL);
area = localtime(&t) ;
printf("Local time is: asctime(area)
gmt = gmt ime(&t);
printfC'GMT is: *s", asctimelgmt)
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/time.h/gmtime/
· short form /3.1/gmtime/