_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 日,协调通用时间 (UTC)。

  • timezone
    区别在于分钟,移动到西,UTC 与本地时间之间。 值 timezone 是从全局变量设置 _timezone 的值 (请参见 _tzset)。

_ftime64,使用 __timeb64 结构,允许文件创建日期,3000 年 12 月 31 日23:59:59,UTC;而 _ftime32 是表示日期2038 年1 月 19 日03:14:07,UTC。 1970 年 1 月 1 日 00:00:00,是所有这些函数的下限的日期范围。

_ftime 与 _ftime64 等效,_timeb 包含 64 位时。 这符合,除非__USE_32BIT_TIME_T 定义旧行为,在实际情况下为;__ftime 使用 32 位时,_timeb 包含 32 位时。

_ftime验证其参数。 如果 timeptr 传递 null 指针,函数会调用无效参数处理程序,如 参数验证 所述。 如果允许执行继续,则该函数返回 -1 并将 errno 设置为 EINVAL。

要求

功能

必需的标头

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

.NET Framework 等效项

System::DateTime::Now

请参见

参考

时间管理

asctime、_wasctime

ctime、_ctime32、_ctime64、_wctime、_wctime32、_wctime64

gmtime、_gmtime32、_gmtime64

localtime、_localtime32、_localtime64

time、_time32、_time64