Temporal.Now.plainTimeISO()

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

Temporal.Now.plainTimeISO() 靜態方法以指定時區返回當前時間,格式為 Temporal.PlainTime 物件。

請注意,雖然該方法名稱中包含“ISO”,但 Temporal.PlainTime 物件沒有關聯的日曆,因為時間格式不依賴於日曆。

語法

js
Temporal.Now.plainTimeISO()
Temporal.Now.plainTimeISO(timeZone)

引數

timeZone 可選

可以是代表解釋系統時間的時區的字串或 Temporal.ZonedDateTime 例項。如果是 Temporal.ZonedDateTime 例項,則使用其時區。如果是字串,可以是命名時區識別符號、偏移時區識別符號,或包含時區識別符號或偏移量的日期時間字串(有關更多資訊,請參閱 時區和偏移量)。

返回值

以指定時區表示的當前時間,格式為 Temporal.PlainTime 物件。其精度與 Temporal.Now.instant() 相同。

異常

RangeError

如果時區無效,則丟擲此異常。

示例

使用 Temporal.Now.plainTimeISO()

js
// The current time in the system's time zone
const time = Temporal.Now.plainTimeISO();
console.log(time); // e.g.: 06:12:34.567890123

// The current time in the "America/New_York" time zone
const timeInNewYork = Temporal.Now.plainTimeISO("America/New_York");
console.log(timeInNewYork); // e.g.: 23:12:34.567890123

規範

規範
Temporal
# sec-temporal.now.plaintimeiso

瀏覽器相容性

另見