The Temporal.PlainDateTime() constructor creates Temporal.PlainDateTime objects.
This constructor allows you to create instances by directly supplying the underlying data. Like all other Temporal classes, you should usually construct Temporal.PlainDateTime objects using the Temporal/PlainDateTime/from static method, which can handle a variety of input types.
Syntax
new Temporal.PlainDateTime(year, month, day)
new Temporal.PlainDateTime(year, month, day, hour)
new Temporal.PlainDateTime(year, month, day, hour, minute)
new Temporal.PlainDateTime(year, month, day, hour, minute, second)
new Temporal.PlainDateTime(year, month, day, hour, minute, second, millisecond)
new Temporal.PlainDateTime(year, month, day, hour, minute, second, millisecond, microsecond)
new Temporal.PlainDateTime(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond)
new Temporal.PlainDateTime(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar)
[!NOTE]
Temporal.PlainDateTime()can only be constructed withnew. Attempting to call it withoutnewthrows 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.
hour- : A number, truncated to an integer, representing the hour component.
minute- : A number, truncated to an integer, representing the minute component.
second- : A number, truncated to an integer, representing the second component.
millisecond- : A number, truncated to an integer, representing the millisecond component.
microsecond- : A number, truncated to an integer, representing the microsecond component.
nanosecond- : A number, truncated to an integer, representing the nanosecond component.
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 thecalendar, theyear,month, anddaymust be in the ISO 8601 calendar system.
- : A string representing the calendar to use. See
Return value
A new Temporal.PlainDateTime object, representing the date-time specified by the parameters.
Exceptions
- RangeError
- : Thrown in one of the following cases:
- Any date-time component is not a finite number.
- The date-time component 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.
calendaris not a valid calendar identifier.
- : Thrown in one of the following cases:
Examples
Using Temporal.PlainDateTime()
const dt = new Temporal.PlainDateTime(2021, 7, 1);
console.log(dt.toString()); // 2021-07-01T00:00:00
const dt2 = new Temporal.PlainDateTime(2021, 7, 1, 0, 0, 0, 0, 0, 0, "hebrew");
console.log(dt2.toString()); // 2021-07-01T00:00:00[u-ca=hebrew]
Specifications
Browser compatibility
See also
- Temporal.PlainDateTime
- Temporal/PlainDateTime/from
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
