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

浏览器兼容性

另见