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

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

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

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

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

要求

功能

必需的标头

_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