共用方式為


_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
    Pointer to a _timeb,__timeb32, or __timeb64 structure.

傳回值

零,如果執行成功、 失敗的錯誤代碼。 如果 timeptr 為 NULL,則傳回值是 EINVAL。

備註

_ftime_s函式會取得目前的當地時間,並將它儲存在結構中所指timeptr*.* The _timeb,__timeb32,and__timeb64 structures are defined in SYS\Timeb.h. 它們包含下列表格中所列的四個欄位。

  • dstflag
    如果日光節約時間是目前作用中的當地時區計算,非零值。 (請參閱 _tzset 如需說明如何決定日光節約時間。)

  • millitm
    毫秒秒數部分。

  • time
    時間 (秒) 午夜 (00: 00: 00)、 1970 年 1 月 1,國際標準時間 (UTC)。

  • timezone
    以分鐘為單位的差異時,切換想知道 UTC 及當地時間。 值為timezone設定全域變數的值從_timezone (請參閱_tzset)。

_ftime64_s使用__timeb64結構,可讓檔案建立日期,以用來表示向上 23: 59: 59 之間,3000 年 12 月 31 UTC。 而_ftime32_s只代表透過 03: 14: 07 以後 2038 年 1 月 19 日,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。

需求

Function

所需的標頭

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

.NET Framework 對等用法

System::DateTime::Now

請參閱

參考

時間管理

asctime _wasctime

ctime、 _ctime32、 _ctime64、 _wctime、 _wctime32、 _wctime64

gmtime,_gmtime32 _gmtime64

localtime,_localtime32 _localtime64

time,_time32 _time64