共用方式為


_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結構的指標。

傳回值

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

備註

_ftime_s 函式取得目前本地時間,並儲存它所指向的結構 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_s,使用 __timeb64 結構,允許檔案建立日期透過 23:59 來表示: 59, 3000 年 12 月 31 日,, UTC;而 _ftime32_s 傳遞 03:14 只代表日期: 07 年 1 月 19 日 2038, UTC。 1970 年 1 月 1 日的午夜是這些函式的時間日期範圍的下界。

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

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

需求

功能

必要的標頭

_ftime_s

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

_ftime32_s

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

_ftime64_s

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

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

程式庫

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

.NET Framework 對等用法

System::DateTime::Now

請參閱

參考

時間管理

asctime、_wasctime

ctime、_ctime32、_ctime64、_wctime、_wctime32、_wctime64

gmtime、_gmtime32、_gmtime64

localtime、_localtime32、_localtime64

time、_time32、_time64