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

Temporal.PlainDate() constructor

· 52CE 我爱测

The **`Temporal.PlainDate()`** constructor creates Temporal.PlainDate objects.

The Temporal.PlainDate() constructor creates Temporal.PlainDate objects.

This constructor allows you to create instances by directly supplying the underlying data. Like all other Temporal classes, you should usually construct Temporal.PlainDate objects using the Temporal/PlainDate/from static method, which can handle a variety of input types.

Syntax

new Temporal.PlainDate(year, month, day)
new Temporal.PlainDate(year, month, day, calendar)

[!NOTE] Temporal.PlainDate() can only be constructed with new. Attempting to call it without new throws a TypeError.

Parameters

  • year
    • : A number, truncated to an integer, representing the year in the ISO calendar system.
  • month
    • : A number, truncated to an integer, representing the month in the ISO calendar system.
  • day
    • : A number, truncated to an integer, representing the day of the month in the ISO calendar system.
  • calendar
    • : A string representing the calendar to use. See Intl.supportedValuesOf() for a list of commonly supported calendar types. Defaults to "iso8601". Note that irrespective of the calendar, the year, month, and day must be in the ISO 8601 calendar system.

Return value

A new Temporal.PlainDate object, representing the date specified by year, month, day (in the ISO calendar), interpreted in the calendar system specified by calendar.

Exceptions

  • TypeError
    • : Thrown if calendar is not a string or undefined.
  • RangeError
    • : Thrown in one of the following cases:
      • year, month, or day is not a finite number.
      • The year, month, and day combination does not represent a valid date in the ISO calendar system, or is not in the representable range, which is ±(10<sup>8</sup> + 1) days, or about ±273,972.6 years, from the Unix epoch.
      • calendar is not a valid calendar identifier.

Examples

Using Temporal.PlainDate()

const plainDate = new Temporal.PlainDate(2021, 7, 1);
console.log(plainDate.toString()); // 2021-07-01

// Note that the date is stored internally as ISO 8601, even when it's
// interpreted in a different calendar system. For example, even though
// 2021-07-01 ISO is 5781-10-21 in the Hebrew calendar, you still pass the
// ISO date to the constructor.
const plainDate2 = new Temporal.PlainDate(2021, 7, 1, "hebrew");
console.log(plainDate2.toString()); // 2021-07-01[u-ca=hebrew]
console.log(plainDate2.year); // 5781
console.log(plainDate2.month); // 10
console.log(plainDate2.day); // 21

Specifications

Browser compatibility

See also

  • Temporal.PlainDate
  • Temporal/PlainDate/from

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

资料来源与适用范围

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

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

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