Export (0) Print
Expand All
div
eof
Expand Minimize
3 out of 7 rated this helpful - Rate this topic

_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 
);

Parameters

_tm

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.

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. If any of the conditions below applies, the function invokes an invalid parameter handler, as described in Parameter Validation.

Error Conditions
_tm time Return Value in _tm

NULL

any

EINVAL

Not modified.

Not NULL (points to valid memory)

NULL

EINVAL

All fields set to -1.

Not NULL

< 0

EINVAL

All fields set to -1.

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.

NoteNote

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.

tm_sec

Seconds after minute (0 – 59).

tm_min

Minutes after hour (0 – 59).

tm_hour

Hours since midnight (0 – 23).

tm_mday

Day of month (1 – 31).

tm_mon

Month (0 – 11; January = 0).

tm_year

Year (current year minus 1900).

tm_wday

Day of week (0 – 6; Sunday = 0).

tm_yday

Day of year (0 – 365; January 1 = 0).

tm_isdst

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.

Routine Required header Compatibility

_gmtime_s

<time.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_gmtime32_s

<time.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_gmtime64_s

<time.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

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

Sample Output

Coordinated universal time is Fri Apr 25 20:12:33 2003

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.