difftime
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <time.h> で定義
|
||
double difftime( time_t time_end, time_t time_beg ); |
||
time_t オブジェクトとしての2つのカレンダー時刻間の差 (time_end - time_beg) の秒数を計算します。 time_end が time_beg より前の時点を参照する場合、結果は負になります。
引数
| time_beg, time_end | - | 比較する時刻 |
戻り値
2つの時刻間の差の秒数。
ノート
POSIX システムでは time_t は秒で測られ difftime は算術減算と同等ですが、 C および C++ は time_t に対して小数点以下の単位も許しています。
例
以下のプログラムは月の始めからの経過した秒数を計算します。
Run this code
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t now;
time(&now);
struct tm beg;
beg = *localtime(&now);
// set beg to the beginning of the month
beg.tm_hour = 0;
beg.tm_min = 0;
beg.tm_sec = 0;
beg.tm_mday = 1;
double seconds = difftime(now, mktime(&beg));
printf("%.f seconds have passed since the beginning of the month.\n", seconds);
return 0;
}
出力:
1937968 seconds have passed since the beginning of the month.
参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.27.2.2 The difftime function (p: 390)
- C99 standard (ISO/IEC 9899:1999):
- 7.23.2.2 The difftime function (p: 339)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.12.2.2 The difftime function
関連項目
difftime の C++リファレンス
|