現在の時刻を取得します。 これらの関数のセキュリティを強化したバージョンを使用できます。「_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> で定義されます。 これらは、次の表に示す 4 つのフィールドを含んでいます。
| フィールド | 説明 |
|---|---|
dstflag |
ローカルのタイム ゾーンで夏時間が現在有効になっている場合は 0 以外の値です (夏時間の決定方法については、 _tzset を参照してください)。 |
millitm |
ミリ秒単位での秒の小数部。 |
time |
世界協定時刻 (UTC: Coordinated Universal Time) の 1970 年 1 月 1 日の深夜 00:00:00 から経過した時間 (秒単位)。 |
timezone |
西に移動するときの UTC と現地時刻の間の差 (分単位)。 timezone の値は、グローバル変数 _timezone の値から設定されます (_tzset を参照してください)。 |
__timeb64構造を使用する_ftime64関数を使用すると、ファイルの作成日を UTC の 23:59:59、3000 年 12 月 31 日まで表すことができます。一方、_ftime32は 2038 年 1 月 18 日 23:59:59 までの日付のみを表します。 これらの関数の日付範囲の下限は、いずれも 1970 年 1 月 1 日の午前 0 時です。
_ftime関数は_ftime64に相当し、_USE_32BIT_TIME_Tが定義されていない限り、_timebには 64 ビットの時刻が含まれます。その場合、古い動作が有効です。_ftimeは 32 ビット時刻を使用し、_timebには 32 ビット時刻が含まれます。
_ftime はそのパラメーターを検証します。 timeptrとして null ポインターを渡した場合、この関数は無効なパラメーター ハンドラーを呼び出します(パラメーター検証で説明されています。 実行の継続が許可された場合、関数は errno を EINVAL に設定します。
既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT でのグローバル状態」を参照してください。
要件
| 機能 | 必須ヘッダー |
|---|---|
_ftime |
<sys/types.h> と <sys/timeb.h> |
_ftime32 |
<sys/types.h> と <sys/timeb.h> |
_ftime64 |
<sys/types.h> と <sys/timeb.h> |
互換性の詳細については、「 Compatibility」を参照してください。
例
// 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
関連項目
時間管理
asctime, _wasctime
ctime、 _ctime32、 _ctime64、 _wctime、 _wctime32、 _wctime64
gmtime、 _gmtime32、 _gmtime64
localtime、 _localtime32、 _localtime64
time、 _time32、 _time64