gmtime - C time.h

C examples for time.h:gmtime

Type

function

From


<ctime>
<time.h>

Description

Convert time_t to tm as UTC time

Prototype

struct tm * gmtime (const time_t * timer);

Parameters

Parameter Description
timer Pointer to an object of type time_t.

Return Value

tm structure value in the UTC time representation of timer.

Demo Code


#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;
}

Related Tutorials