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

浏览器兼容性

另见