Share via


gmtime_s, _gmtime32_s, _gmtime64_s

转换时间值为结构。 这些是 _gmtime32, _gmtime64 的版本与安全增强的 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 
);

参数

  • _tm
    为 tm 结构的指针。 返回的结构的字段表示 timer 参数的计算的值 UTC 的而不是在本地时间。

  • time
    为内存的指针。 时间表示为秒自午夜 (00:00 elapsed: 00), 1970 年一月 1 日,世界 (UTC)时 (utc)。

返回值

零,如果成功。 ,如果有错误,则返回值是错误代码。 错误代码。 Errno.h 定义;有关列出了这些错误,请参见 errno

错误状态

_tm

time

Return

在 _tm的值

NULL

任何

EINVAL

不修改。

不是 NULL (指向有效的内存)

NULL

EINVAL

所有字段设置为 -1。

不是 NULL

< 0

EINVAL

所有字段设置为 -1。

在前两个错误条件,无效参数调用处理程序,如 参数验证所述。 如果执行允许继续,对 EINVAL 的这些功能集 errno 和返回 EINVAL。

备注

_gmtime32_s 功能在类型 tm结构分区 time 值并将其存储,定义在 Time.h。 结构的地址。 _tm通过。 time 的值在调用通常获取到 time 功能。

备注

目标环境应尝试确定夏时制时间是否有效。C 运行库假定实现的夏时制的计算美国规则。

如下表所示,每个结构字段是类型, int。

  • tm_sec
    秒数分钟 (0 – 59) 之后。

  • tm_min
    分钟数小时 (0 – 59) 之后。

  • tm_hour
    小时数自午夜 (0 – 23)。

  • tm_mday
    日期月份 (1 – 31)。

  • tm_mon
    月份 (0 – 11;一月 = 0)。

  • tm_year
    年份 (减号 1900 的当前年份)。

  • tm_wday
    每周日期 (0 – 6;sunday = 0)。

  • tm_yday
    日、 (0 – 365;一月 1 日 = 0 日)。

  • tm_isdst
    始终 0 gmtime的。

_gmtime64_s,使用 __time64_t 结构,允许日期下午 23:59 表示: 59, 3000 年十二月 31 日,, UTC;而 gmtime32_s 下午 03:14 只表示日期: 一月 07 日 19 日 2038 中, UTC。 午夜, 1970 年一月 1 日,是日期范围的下限这些功能的。

gmtime_s 是计算结果为 _gmtime64_s ,并 time_t 与 __time64_t等效的内联函数。 如果需要强制编译器解释 time_t 为旧 32 位 time_t,可以定义 _USE_32BIT_TIME_T。 这样做将导致 gmtime_s 联机获取对 _gmtime32_s。 建议不要这样做,因为应用程序可以在 2038 年一月 18 日之后,失败,并且在 64 位平台不允许的。

要求

实例

必需的头

gmtime_s

time.h

_gmtime32_s

time.h

_gmtime64_s

time.h

有关更多兼容性信息,请参见中介绍的 兼容性

示例

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

.NET Framework 等效项

请参见

参考

时间线

asctime_s, _wasctime_s

ctime, _ctime32, _ctime64, _wctime, _wctime32, _wctime64

_ftime, _ftime32, _ftime64

gmtime, _gmtime32, _gmtime64

localtime_s, _localtime32_s, _localtime64_s

_mkgmtime, _mkgmtime32, _mkgmtime64

mktime, _mktime32, _mktime64

time, _time32, _time64