Exporter (0) Imprimer
Développer tout
Développer Réduire

_gmtime_s, _gmtime32_s, _gmtime64_s

Converts a time value to a structure. These are versions of _gmtime32, _gmtime64 with security enhancements as described in Security Enhancements in the CRT.

errno_t _gmtime_s(
   struct tm* _tm,
   const __time_t* time
errno_t _gmtime32_s(
   struct tm* _tm,
   const __time32_t* time
errno_t _gmtime64_s(
   struct tm* _tm,
   const __time64_t* time 


Pointer to a tm structure. The fields of the returned structure hold the evaluated value of the timer argument in UTC rather than in local time.


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

Zero if successful. The return value is an error code if there is a failure. Error codes are defined in Errno.h; for a listing of these errors, see errno.

Error Conditions




Value in _tm




Not modified.

Not NULL (points to valid memory)



All fields set to -1.


< 0


All fields set to -1.

In the case of the first two error conditions, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, these functions set errno to EINVAL and return EINVAL.

The _gmtime32_s function breaks down the time value and stores it in a statically allocated structure of type tm, defined in Time.h. The value of time is usually obtained from a call to the time function.

Note 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 .

Each of the structure fields is of type int, as shown in the following table.


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.

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

In Visual C++ 2005, gmtime_s is an inline function which evaluates to _gmtime64_s and time_t is equivalent to __time64_t. If you need to force the compiler to interpret time_t as the old 32-bit time_t, you can define _USE_32BIT_TIME_T. Doing this will cause gmtime_s to be in-lined to _gmtime32_s. This is not recommended because your application may fail after January 18, 2038, and it is not allowed on 64-bit platforms.


Required header







For more compatibility information, see Compatibility in the Introduction.

// crt_gmtime64_s.c
// This program uses _gmtime64_s to convert a 64-bit
// integer representation of coordinated universal time
// to a structure named newtime, then uses asctime_s to
// convert this structure to an output string.

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

int main( void )
   struct tm newtime;
   __int64 ltime;
   char buf[26];
   errno_t err;

   _time64( &ltime );

   // Obtain coordinated universal time: 
   err = _gmtime64_s( &newtime, &ltime );
   if (err)
      printf("Invalid Argument to _gmtime64_s.");
   // Convert to an ASCII representation 
   err = asctime_s(buf, 26, &newtime);
   if (err)
      printf("Invalid Argument to asctime_s.");

   printf( "Coordinated universal time is %s\n", 
           buf );
Coordinated universal time is Fri Apr 25 20:12:33 2003

Ajouts de la communauté

© 2014 Microsoft