cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : ctime (time.h) : gmtime
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
ctime (time.h)
functions:
· asctime
· clock
· ctime
· difftime
· gmtime
· localtime
· mktime
· strftime
· time
macros:
· CLOCKS_PER_SEC
· NULL
types:
· clock_t
· size_t
· time_t
· struct tm

-

gmtime function
struct tm * gmtime ( const time_t * timer );
<ctime>

Convert time_t to tm as UTC time

Uses the value pointed by timer to fill a tm structure with the values that represent the corresponding time, expressed as UTC (or GMT timezone).

Parameters

timer
Pointer to a time_t value representing a calendar time (see time_t).

Return Value

A pointer to a tm structure with the time information filled in.

This structure is statically allocated and shared by the functions gmtime and localtime. Each time either one of these functions is called the contents of this structure is overwritten.

Example

/* gmtime example */
#include <stdio.h>
#include <time.h>

#define MST (-7)
#define UTC (0)
#define CCT (+8)

int main ()
{
  time_t rawtime;
  tm * ptm;

  time ( &rawtime );

  ptm = gmtime ( &rawtime );

  puts ("Current time around the World:");
  printf ("Phoenix, AZ (U.S.) :  %2d:%02d\n", (ptm->tm_hour+MST)%24, ptm->tm_min);
  printf ("Reykjavik (Iceland) : %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;
}

Output:


Current time around the World:
Phoenix, AZ (U.S.) : 8:26
Reykjavik (Iceland) : 15:26
Beijing (China) : 23:26

See also

asctime Convert tm structure to string (function)
ctime Convert time_t value to string (function)
localtime Convert time_t to tm as local time (function)
mktime Convert tm structure to time_t (function)
time Get current time (function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us