C の time() 関数
time() 関数は、time.h (C++ では ctime) ヘッダー ファイルで定義されます。この関数は、1970 年 1 月 1 日 00:00:00 UTC (Unix タイムスタンプ) からの時間を秒単位で返します。 Second が NULL ポインタでない場合、戻り値は Second が指すオブジェクトにも格納されます。
構文:
time_t time( time_t *second )
パラメータ: この関数は単一のパラメータを受け取ります 2番 。このパラメータは、時刻を格納する time_t オブジェクトを設定するために使用されます。
戻り値: この関数は、現在のカレンダー時間を time_t 型のオブジェクトとして返します。
時間計算量: ○(1)
補助スペース: ○(1)
プログラム 1:
C
// C program to demonstrate> // example of time() function.> #include> #include> int> main ()> {> > time_t> seconds;> > > seconds => time> (NULL);> > printf> (> 'Seconds since January 1, 1970 = %ld
'> , seconds);> > > return> (0);> }> |
出力:
Seconds since January 1, 1970 = 1538123990
例 2:
C
// C program to demonstrate> // example of time() function.> > #include> #include> > int> main()> {> > time_t> seconds;> > > // Stores time seconds> > time> (&seconds);> > printf> (> 'Seconds since January 1, 1970 = %ld
'> , seconds);> > > return> 0;> }> |
出力:
Seconds since January 1, 1970 = 1538123990