Date.prototype.getSeconds()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
getSeconds() は Date インスタンスのメソッドで、地方時に基づき、指定した日時の「秒」を返します。
試してみましょう
const moonLanding = new Date("July 20, 69 00:20:18");
console.log(moonLanding.getSeconds());
// 予想される結果: 18
構文
js
getSeconds()
引数
なし。
返値
地方時に基づき、指定された日時の「秒」を表す 0 から 59 までの間の整数値です。日時が無効な場合は NaN を返します。
例
>getSeconds() の使用
変数 seconds には、 Date オブジェクト xmas95 に基づいて、 30 という値が入ります。
js
const xmas95 = new Date("1995-12-25T23:15:30");
const seconds = xmas95.getSeconds();
console.log(seconds); // 30
仕様書
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-date.prototype.getseconds> |
ブラウザーの互換性
Loading…