Share via


_ftime_s, _ftime32_s, _ftime64_s

取得目前時間。 這些函式是 的版本 _ftime_ftime32_ftime64 具有 CRT 中安全性功能中所述 的安全性增強功能。

語法

errno_t _ftime_s( struct _timeb *timeptr );
errno_t _ftime32_s( struct __timeb32 *timeptr );
errno_t _ftime64_s( struct __timeb64 *timeptr );

參數

timeptr
_timeb__timeb32__timeb64 結構的指標。

傳回值

如果成功,則為零,如果失敗,則為錯誤碼。 如果 timeptrNULL,則傳回值是 EINVAL

備註

_ftime_s 式會取得目前的當地時間,並將它儲存在 所 timeptr 指向的結構中。 _timeb__timeb32__timeb64 結構定義于 SYS\Timeb.h 中。 它們包含下表中所列出的四個欄位。

欄位 描述
dstflag 若日光節約時間目前於本地時區已生效,則為非零。 (如需如何決定日光節約時間的說明,請參閱 _tzset
millitm 秒數的分數,以毫秒為單位。
time 自國際標準時間 (UTC) 1970 年 1 月 1 日午夜 (00:00:00) 以來的時間,以秒為單位。
timezone UTC 和當地時間之間的時差,向西推進,以分鐘為單位。 timezone 的值由全域變數 _timezone 的值設定 (請參閱 _tzset)。

_ftime64_s 式會使用 __timeb64 結構,可讓檔案建立日期以 23:59:59、3000 年 12 月 31 日 UTC 表示;而 _ftime32_s 只代表日期到 2038 年 1 月 18 日 23:59:59,UTC。 1970 年 1 月 1 日午夜是所有這些函式的日期範圍下限。

_ftime_s 式相當於 _ftime64_s ,而且 _timeb 包含 64 位時間,除非 _USE_32BIT_TIME_T 已定義,否則舊行為有效 _ftime_s ;使用 32 位時間,並 _timeb 包含 32 位時間。

_ftime_s 會驗證其參數。 如果傳遞 Null 指標做為 timeptr ,則函式會叫用不正確參數處理常式,如參數驗證 中所述 。 如果允許繼續執行,則函式會將 errno 設為 EINVAL

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

函式 必要的標頭
_ftime_s <sys/types.h > 和 < sys/timeb.h>
_ftime32_s <sys/types.h > 和 < sys/timeb.h>
_ftime64_s <sys/types.h > 和 < sys/timeb.h>

如需相容性詳細資訊,請參閱相容性

程式庫

所有版本的 C 執行階段程式庫

範例

// crt_ftime64_s.c
// This program uses _ftime64_s to obtain the current
// time and then stores this time in timebuffer.

#include <stdio.h>
#include <sys/timeb.h>
#include <time.h>

int main( void )
{
   struct _timeb timebuffer;
   char timeline[26];
   errno_t err;
   time_t time1;
   unsigned short millitm1;
   short timezone1;
   short dstflag1;

   _ftime64_s( &timebuffer );

    time1 = timebuffer.time;
    millitm1 = timebuffer.millitm;
    timezone1 = timebuffer.timezone;
    dstflag1 = timebuffer.dstflag;

   printf( "Seconds since midnight, January 1, 1970 (UTC): %I64d\n",
   time1);
   printf( "Milliseconds: %d\n", millitm1);
   printf( "Minutes between UTC and local time: %d\n", timezone1);
   printf( "Daylight savings time flag (1 means Daylight time is in "
           "effect): %d\n", dstflag1);

   err = ctime_s( timeline, 26, & ( timebuffer.time ) );
   if (err)
   {
       printf("Invalid argument to ctime_s. ");
   }
   printf( "The time is %.19s.%hu %s", timeline, timebuffer.millitm,
           &timeline[20] );
}
Seconds since midnight, January 1, 1970 (UTC): 1051553334
Milliseconds: 230
Minutes between UTC and local time: 480
Daylight savings time flag (1 means Daylight time is in effect): 1
The time is Mon Apr 28 11:08:54.230 2003

另請參閱

時間管理
asctime, _wasctime
ctime, _ctime32, _ctime64, _wctime, _wctime32, _wctime64
gmtime, _gmtime32, _gmtime64
localtime, _localtime32, _localtime64
time, _time32, _time64