Date.prototype.getUTCSeconds()

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

getUTCSeconds() 方法屬於 Date 例項,它根據世界時返回指定日期中的秒數。

試一試

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

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

語法

js
getUTCSeconds()

引數

無。

返回值

一個介於 0 到 59 之間的整數,表示根據世界時給定的日期的秒數。如果日期 無效,則返回 NaN

示例

使用 getUTCSeconds()

以下示例將當前時間的秒數部分賦給變數 seconds

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

規範

規範
ECMAScript® 2026 語言規範
# sec-date.prototype.getutcseconds

瀏覽器相容性

另見