Share via


_ftime, _ftime32, _ftime64

取得目前時間。 這些函式有更安全的版本可供使用;請參閱 、、 _ftime64_s_ftime32_s_ftime_s

語法

void _ftime( struct _timeb *timeptr );
void _ftime32( struct __timeb32 *timeptr );
void _ftime64( struct __timeb64 *timeptr );

參數

timeptr
_timeb__timeb32__timeb64 結構的指標。

備註

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

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

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

_ftime 式相當於 _ftime64 ,且 _timeb 包含 64 位時間,除非 _USE_32BIT_TIME_T 已定義,在此情況下,舊行為有效; _ftime 使用 32 位時間,並 _timeb 包含 32 位時間。

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

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

需求

函式 必要的標頭
_ftime <sys/types.h > 和 < sys/timeb.h>
_ftime32 <sys/types.h > 和 < sys/timeb.h>
_ftime64 <sys/types.h > 和 < sys/timeb.h>

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

範例

// crt_ftime.c
// compile with: /W3
// This program uses _ftime 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;

   _ftime( &timebuffer ); // C4996
   // Note: _ftime is deprecated; consider using _ftime_s instead

   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