_ftime, _ftime32, _ftime64
Get the current time. More secure versions of these functions are available; see _ftime_s, _ftime32_s, _ftime64_s.
void _ftime( struct _timeb *timeptr ); void _ftime32( struct __timeb32 *timeptr ); void _ftime64( struct __timeb64 *timeptr );
The _ftime function gets the current local time and stores it in the structure pointed to by timeptr. The _timeb, __timeb32,and__timeb64 structures are defined in SYS\Timeb.h. They contain four fields, which are listed in the following table.
_ftime64, which uses the __timeb64 structure, allows file-creation dates to be expressed up through 23:59:59, December 31, 3000, UTC; whereas _ftime32 only represents dates through 03:14:07 January 19, 2038, UTC. Midnight, January 1, 1970, is the lower bound of the date range for all these functions.
_ftime is equivalent to _ftime64 and _timeb contains a 64-bit time. This is true unless _USE_32BIT_TIME_T is defined, in which case the old behavior is in effect; _ftime uses a 32-bit time and _timeb contains a 32-bit time.
_ftime validates its parameters. If passed a null pointer as timeptr, the function invokes the invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, the function sets errno to EINVAL.
Function | Required header |
|---|---|
_ftime | <sys/types.h> and <sys/timeb.h> |
_ftime32 | <sys/types.h> and <sys/timeb.h> |
_ftime64 | <sys/types.h> and <sys/timeb.h> |
For more compatibility information, see Compatibility in the Introduction.
// 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] );
}
Seconds since midnight, January 1, 1970 (UTC): 1051553334 Milliseconds: 230 Minutes between UTC and local time: 480 Daylight savings time flag (1 means Daylight time is in effect): 1 The time is Mon Apr 28 11:08:54.230 2003