获取当前时间。这些是 _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 日,世界 (UTC)时 (utc)。timezone
区别在于分钟,移动到西, UTC 和本地时间之间。timezone 的值从全局变量设置 _timezone 的值 (请参见 _tzset)。
_ftime64_s,使用 __timeb64 结构,这允许文件创建日期下午 23:59 表示: 59, 3000 年十二月 31 日,, UTC;而 _ftime32_s 下午 03:14 只表示日期: 一月 07 日 19 日 2038 中, UTC。午夜, 1970 年一月 1 日,是日期范围的下限所有这些功能。
_ftime_s 与 _ftime64_s 等效,并 _timeb 包含一个 64 位时间。为 true,除非 _USE_32BIT_TIME_T 定义,因此,在旧行为实际情况下为;_ftime_s 使用 32 位时间,并 _timeb 包含 32 位时间。
_ftime_s 验证其参数。如果传递一个 null 指针作为 timeptr,该函数调用的参数无效处理程序,如 参数验证所述。如果执行允许继续,该功能集 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 等效项
请参见
参考
ctime, _ctime32, _ctime64, _wctime, _wctime32, _wctime64