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 July 2015.

getSeconds() メソッドは、地方時に基づき、指定した日時の「秒」を返します。

試してみましょう

const moonLanding = new Date("July 20, 69 00:20:18");

console.log(moonLanding.getSeconds());
// Expected output: 18

構文

js
getSeconds()

返値

地方時に基づき、与えた日付の「秒」を表す 0 から 59 までの間の整数値。

getSeconds() の使用

以下の 2 行目の文は、Date オブジェクトである xmas95 の値に基づき、変数 seconds に 30 という値を代入します。

js
const xmas95 = new Date("December 25, 1995 23:15:30");
const seconds = xmas95.getSeconds();

console.log(seconds); // 30

仕様書

Specification
ECMAScript® 2025 Language Specification
# sec-date.prototype.getseconds

ブラウザーの互換性

BCD tables only load in the browser

関連情報