現在の時刻を取得します。 これらの関数は、「CRT のセキュリティ機能で説明されているように、セキュリティが強化された_ftime、_ftime32、_ftime64のバージョンです。
構文
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構造体へのポインター。
戻り値
正常終了した場合は 0 を返します。失敗した場合はエラー コードを返します。 timeptr が NULL の場合、戻り値は EINVAL です。
解説
_ftime_s関数は、現在の現地時刻を取得し、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_s関数を使用すると、ファイルの作成日を UTC の 23:59:59、3000 年 12 月 31 日まで表すことができます。一方、_ftime32_sは 2038 年 1 月 18 日 23:59:59 までの日付のみを表します。 これらの関数の日付範囲の下限は、いずれも 1970 年 1 月 1 日の午前 0 時です。
_ftime_s関数は_ftime64_sに相当し、_timebには 64 ビットの時刻が含まれますが、_USE_32BIT_TIME_Tが定義されていない限り、古い動作が有効になります。_ftime_sは 32 ビット時刻を使用し、_timebには 32 ビット時刻が含まれます。
_ftime_s はそのパラメーターを検証します。 timeptrとして null ポインターを渡した場合、この関数は無効なパラメーター ハンドラーを呼び出します(パラメーター検証で説明されています。 実行の継続が許可された場合、関数は errno を EINVAL に設定します。
既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT でのグローバル状態」を参照してください。
要件
| 機能 | 必須ヘッダー |
|---|---|
_ftime_s |
<sys/types.h> と <sys/timeb.h> |
_ftime32_s |
<sys/types.h> と <sys/timeb.h> |
_ftime64_s |
<sys/types.h> と <sys/timeb.h> |
互換性の詳細については、「 Compatibility」を参照してください。
ライブラリ
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] );
}
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