gmtime
struct tm * gmtime ( const time_t * timer ); | time.h |
cplusplus.com |
Convert time_t value to tm structure as UTC time.
Converts timer to tm structure adjusting to UTC (formerly
known as GMT) timezone.
Parameters.
Return Value.
A pointer to a tm structure.
This structure is statically allocated and shared by gmtime,
localtime and ctime functions.
Each time one of these functions
is called the content of the structure is overwritten.
Portability.
Defined in ANSI-C.
Example.
/* gmtime example */
#include <stdio.h>
#include <time.h>
#define PST (-8)
#define CET (1)
#define HKG (8)
main ()
{
time_t rawtime;
tm * ptm;
time ( &rawtime );
ptm = gmtime ( &rawtime );
printf ("Time in Los Angeles: %2d:%02d\n", ptm->tm_hour+PST, ptm->tm_min);
printf ("Time in Berlin: %2d:%02d\n", ptm->tm_hour+CET, ptm->tm_min);
printf ("Time in Hong Kong: %2d:%02d\n", ptm->tm_hour+HKG, ptm->tm_min);
return 0;
}
Output:
Time in Los Angeles: 7:26
Time in Berlin: 16:26
Time in Hong Kong: 23:26
See also.
asctime,
ctime,
localtime,
mktime,
time