Date.prototype.getUTCSeconds()

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.

getUTCSeconds() メソッドは、協定世界時に基づき、指定された日時の「秒」を返します。

試してみましょう

const moonLanding = new Date("July 20, 1969, 20:18:04 UTC");

console.log(moonLanding.getUTCSeconds());
// Expected output: 4

構文

js
getUTCSeconds()

返値

数値です。 もし Date オブジェクトが有効な日時を表している場合は、0 から 59 までの整数で、指定された日時の世界時での秒の値を表します。 それ以外の場合は、Date オブジェクトが有効な日時を表していなければ NaN が返されます。

getUTCSeconds() の使用

次の例は、現在日時の「秒」部を変数 seconds に代入します。

js
const today = new Date();
const seconds = today.getUTCSeconds();

仕様書

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

ブラウザーの互換性

BCD tables only load in the browser

関連情報