gmtime, _gmtime64
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

gmtime, _gmtime64

Convert a time value to a structure.

struct tm *gmtime( 
   const time_t *timer 
struct tm *_gmtime64( 
   const __time64_t *timer 


Pointer to stored time. The time is represented as seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC).

Return Value

Return a pointer to a structure of type tm. The fields of the returned structure hold the evaluated value of the timer argument in UTC rather than in local time. Each of the structure fields is of type int, as follows:

Seconds after minute (0 – 59).
Minutes after hour (0 – 59).
Hours since midnight (0 – 23).
Day of month (1 – 31).
Month (0 – 11; January = 0).
Year (current year minus 1900).
Day of week (0 – 6; Sunday = 0).
Day of year (0 – 365; January 1 = 0).
Always 0 for gmtime.

The gmtime, mktime, and localtime functions use the same single, statically allocated structure to hold their results. Each call to one of these functions destroys the result of any previous call. If timer represents a date before midnight, January 1, 1970, gmtime returns NULL. There is no error return.

_gmtime64, which uses the __time64_t structure, allows dates to be expressed up through 23:59:59, December 31, 3000, UTC, whereas gmtime only represent dates through 19:14:07 January 18, 2038, UTC. Midnight, January 1, 1970, is the lower bound of the date range for both these functions.


The gmtime function breaks down the timer value and stores it in a statically allocated structure of type tm, defined in TIME.H. The value of timer is usually obtained from a call to the time function.

Note   The target environment should try to determine whether daylight savings time is in effect. The C run-time library assumes the United States rules for implementing the calculation of Daylight Saving Time (DST).


Routine Required header Compatibility
gmtime <time.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
_gmtime64 <time.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// crt_gmtime.c
/* This program uses _gmtime64 to convert a long-
 * integer representation of coordinated universal time
 * to a structure named newtime, then uses asctime to
 * convert this structure to an output string.

#include <time.h>
#include <stdio.h>

int main( void )
   struct tm *newtime;
   __int64 ltime;

   _time64( &ltime );

   /* Obtain coordinated universal time: */
   newtime = _gmtime64( &ltime );
   printf( "Coordinated universal time is %s\n", 
                               asctime( newtime ) );

Sample Output

Coordinated universal time is Tue Feb 12 23:11:31 2002

See Also

Time Management Routines | asctime | ctime | _ftime | localtime | mktime | time | Run-Time Routines and .NET Framework Equivalents

© 2015 Microsoft