C examples for time.h:gmtime
function
<ctime> <time.h>
Convert time_t to tm as UTC time
struct tm * gmtime (const time_t * timer);
Parameter | Description |
---|---|
timer | Pointer to an object of type time_t. |
tm structure value in the UTC time representation of timer.
#include <stdio.h> #include <time.h> #define MST (-7)/*from www.j av a 2 s . co m*/ #define UTC (0) #define CCT (+8) int main () { time_t rawtime; struct tm * ptm; time ( &rawtime ); ptm = gmtime ( &rawtime ); printf ("Phoenix, AZ (U.S.) : %2d:%02d\n", (ptm->tm_hour+MST)%24, ptm->tm_min); printf ("UTC : %2d:%02d\n", (ptm->tm_hour+UTC)%24, ptm->tm_min); printf ("Beijing (China) : %2d:%02d\n", (ptm->tm_hour+CCT)%24, ptm->tm_min); return 0; }