大网数据广告活动
Web 标准与前端开发

Temporal.Now

· 52CE 我爱测

The **`Temporal.Now`** namespace object contains static methods for getting the current time in various formats.

The Temporal.Now namespace object contains static methods for getting the current time in various formats.

Description

Unlike most global objects, Temporal.Now is not a constructor. You cannot use it with the new operator or invoke the Temporal.Now object as a function. All properties and methods of Temporal.Now are static (just like the Math object).

Most fundamentally, the system time is returned by the operating system as a time since the Unix epoch. Temporal/Now/instant returns this time as a Temporal.Instant object. Although this object can represent nanoseconds, the resolution of the current time depends on the system clock and browser settings.

An instant can be interpreted in a time zone (which is the system time zone Temporal/Now/timeZoneId by default) in the same fashion as Temporal/Instant/toZonedDateTimeISO. To get a Temporal.ZonedDateTime object, you can use Temporal/Now/zonedDateTimeISO. You can also get different parts of the date and time, using Temporal/Now/plainDateISO, Temporal/Now/plainTimeISO, and Temporal/Now/plainDateTimeISO.

For example, if the computer is set to the time zone "America/New_York", Temporal.Now.zonedDateTimeISO() returns a zoned date-time like: 2021-08-01T10:40:12.345-04:00[America/New_York]. In this case, Temporal.Now.plainTimeISO() would return the time part of this zoned date-time: 10:40:12.345. However, if you call Temporal.Now.plainTimeISO("UTC"), it returns the time part of the zoned date-time in the UTC time zone: 14:40:12.345. This is especially useful for cross-system communication where the other end may be expecting the time in a different time zone.

Reduced time precision

To offer protection against timing attacks and fingerprinting, the precision of the current time returned by the Temporal.Now methods may be reduced depending on browser settings.

In Chrome, the rounding interval is 0.1 ms, or 0.005 ms in cross-origin-isolated contexts.

In Firefox, these methods obtain the current time in the same way as Date.now(). They inherit the precision of that clock reading without introducing additional inaccuracy. The timestamp is always an integer number of milliseconds, so its resolution is limited to 1 ms in all contexts. Accessing epochNanoseconds does not increase its precision.

Static properties

  • Temporal.Now[Symbol.toStringTag]
    • : The initial value of the [Symbol.toStringTag] property is the string "Temporal.Now". This property is used in Object.prototype.toString().

Static methods

  • Temporal/Now/instant
    • : Returns the current time as a Temporal.Instant object.
  • Temporal/Now/plainDateISO
    • : Returns the current date as a Temporal.PlainDate object, in the ISO 8601 calendar and the specified time zone.
  • Temporal/Now/plainDateTimeISO
    • : Returns the current date and time as a Temporal.PlainDateTime object, in the ISO 8601 calendar and the specified time zone.
  • Temporal/Now/plainTimeISO
    • : Returns the current time as a Temporal.PlainTime object, in the specified time zone.
  • Temporal/Now/timeZoneId
  • Temporal/Now/zonedDateTimeISO
    • : Returns the current date and time as a Temporal.ZonedDateTime object, in the ISO 8601 calendar and the specified time zone.

Specifications

Browser compatibility

See also

  • Temporal
  • Temporal.Instant
  • Temporal.PlainDate
  • Temporal.PlainDateTime
  • Temporal.PlainTime
  • Temporal.ZonedDateTime

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。