共用方式為


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: 00)、 1970 年 1 月 1,國際標準時間 (UTC)。

傳回值

如果成功的話,則為零。 如果失敗,傳回的值會是一個錯誤碼。 錯誤代碼被定義在 Errno.h; 如需這些錯誤的清單,請參閱 errno

錯誤狀況

_tm

time

Return

在 [值_tm

NULL

任何

EINVAL

不會修改。

不NULL (指向有效的記憶體)

NULL

EINVAL

所有的欄位設定為-1。

不NULL

< 0

EINVAL

所有的欄位設定為-1。

如果是第一個的兩個錯誤條件,不正確的參數處理常式會叫用,如所述參數驗證。 如果執行,則允許繼續執行,這些函式會設定errno到EINVAL ,並傳回EINVAL。

備註

_gmtime32_s函式會分解, time的值,並將它存放在型別的結構tm,已定義在 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。 年 1 月 = 0)。

  • tm_year
    年份 (目前年份減 1900年)。

  • tm_wday
    星期幾 (0 – 6。 星期日 = 0)。

  • tm_yday
    年中的日 (0 – 365。 1 月 1 日 = 0)。

  • tm_isdst
    通常為 0 的gmtime。

_gmtime64_s使用__time64_t結構,可讓日期來表示向上 23: 59: 59 之間,3000 年 12 月 31 UTC。 而gmtime32_s只能代表透過 03: 14: 07 以後 2038 年 1 月 19 日,UTC 日期。 午夜 1970 年 1 月 1 日,會為這些函式之日期範圍的下限。

gmtime_s是內嵌函式評估_gmtime64_s和time_t相當於__time64_t。 如果您要強制編譯器解譯time_t為舊的 32 位元time_t,您可以定義_USE_32BIT_TIME_T。 如此一來,這會導致gmtime_s是在-分行, _gmtime32_s。 建議您不要因為您的應用程式可能會失敗之後 2038 年 1 月 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