共用方式為


_ftime、_ftime32、_ftime64

取得目前時間。 這些函式已有更安全的版本可用,請參閱 _ftime_s、_ftime32_s、_ftime64_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
    秒數 (從 00:00: 00), 1970 年 1 月 1 日, Coordinated Universal Time (UTC)。

  • timezone
    差異的分鐘,移至西, UTC 與本地時間之間。 timezone 的值是從這個全域變數設定 _timezone 的值 (請參閱 _tzset)。

_ftime64,使用 __timeb64 結構,允許檔案建立日期透過 UTC 3000 年 12 月 31 日 23:59 : 59來表示;而 _ftime32 傳遞只代表日期 UTC 2038 年 1 月 19 日 03:14: 07。 1970 年 1 月 1 日的午夜是這些函式的時間日期範圍的下界。

_ftime 與 _ftime64 等價, _timeb ,包含 64 位元的時間。 除非定義 _USE_32BIT_TIME_T ,此時會是舊版的行為, _ftime 使用 32 位元的時間,而 _timeb 包含 32 位元的時間。

_ftime 會驗證其參數。 如果傳遞一個空指標如 timeptr,則函式叫用無效參數處理常式,如參數驗證 中所述。 如果執行允許繼續,對 EINVAL的函式會設定 errno 。

需求

功能

必要的標頭

_ftime

<sys/types.h> 和 <sys/timeb.h>

_ftime32

<sys/types.h> 和 <sys/timeb.h>

_ftime64

<sys/types.h> 和 <sys/timeb.h>

如需更多關於相容性的資訊,請參閱入門介紹中的 相容性 (Compatibility)

範例

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

.NET Framework 對等用法

System::DateTime::Now

請參閱

參考

時間管理

asctime、_wasctime

ctime、_ctime32、_ctime64、_wctime、_wctime32、_wctime64

gmtime、_gmtime32、_gmtime64

localtime、_localtime32、_localtime64

time、_time32、_time64