名前空間
変種
操作

time

From cppreference.com
< c‎ | chrono
ヘッダー <time.h> で定義
time_t time( time_t* arg );

time_t オブジェクトとしてエンコードされた現在のカレンダ時刻を返します。また、arg がヌルポインタでない限り、arg が指す time_t オブジェクトにも格納します。

目次

[編集] Parameters

arg - 時刻が格納される time_t オブジェクトへのポインタ、またはヌルポインタ。

[編集] Return value

成功時は time_t オブジェクトとしてエンコードされた現在のカレンダ時刻、エラー時は (time_t)(-1)arg がヌルポインタでない場合、戻り値は arg が指すオブジェクトにも格納されます。

[編集] Notes

time_t におけるカレンダ時刻のエンコーディングは未指定ですが、ほとんどのシステムは POSIX 仕様に準拠しており、エポックからの秒数を保持する整数型を返します。 time_t が 32 ビット符号付き整数である実装(多くの歴史的な実装)は、2038 年に問題が発生します。

[編集] Example

#include <stdint.h>
#include <stdio.h>
#include <time.h>
 
int main(void)
{
    time_t result = time(NULL);
    if (result != (time_t)(-1))
        printf("The current time is %s(%jd seconds since the Epoch)\n",
               asctime(gmtime(&result)), (intmax_t)result);
}

実行結果の例

The current time is Fri Apr 24 15:05:25 2015
(1429887925 seconds since the Epoch)

[編集] References

  • C23標準 (ISO/IEC 9899:2024)
  • 7.27.2.4 The time function (p: TBD)
  • C17標準 (ISO/IEC 9899:2018)
  • 7.27.2.4 The time function (p: 286)
  • C11標準 (ISO/IEC 9899:2011)
  • 7.27.2.4 The time function (p: 391)
  • C99標準 (ISO/IEC 9899:1999)
  • 7.23.2.4 The time function (p: 341)
  • C89/C90標準 (ISO/IEC 9899:1990)
  • 4.12.2.4 The time function

[編集] See also

エポックからの時間を、地方時で表されるカレンダー時間に変換する
(関数) [編集]
エポックからの時間を、協定世界時 (UTC) で表されるカレンダー時間に変換する
(関数) [編集]
与えられた時間基準に基づいて、カレンダー時間を秒とナノ秒で返す
(関数) [編集]
C++ ドキュメントtime について)
English 日本語 中文(简体) 中文(繁體)