Temporal.Now.plainDateISO()

可用性有限

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

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

Temporal.Now.plainDateISO() 靜態方法以 ISO 8601 日曆和指定時區,返回當前日期,格式為 Temporal.PlainDate 物件。

語法

js
Temporal.Now.plainDateISO()
Temporal.Now.plainDateISO(timeZone)

引數

timeZone 可選

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

返回值

以 ISO 8601 日曆格式,在指定時區中,返回當前日期,格式為 Temporal.PlainDate 物件。

異常

RangeError

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

示例

使用 Temporal.Now.plainDateISO()

js
// The current date in the system's time zone
const date = Temporal.Now.plainDateISO();
console.log(date); // e.g.: 2021-10-01

// The current date in the "America/New_York" time zone
const dateInNewYork = Temporal.Now.plainDateISO("America/New_York");
console.log(dateInNewYork); // e.g.: 2021-09-30

規範

規範
Temporal
# sec-temporal.now.plaindateiso

瀏覽器相容性

另見