bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/JavaScript/Objects, Classes, and Advanced Patterns
JavaScript•Objects, Classes, and Advanced Patterns

JavaScript PlainDateTime

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind JavaScript PlainDateTime?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

// ___ a PlainDateTime object
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Create a PlainDateTime with new
How to Create a PlainDateTime Object
The Temporal.PlainDateTime Object

The Temporal.PlainDateTime Object

The Temporal.PlainDateTime object is a pure date and time object .

It represents a calendar date and a wall-clock time with no time zone.

Example: 2026-05-07T14:30:00 .

Example

// Create a PlainDateTime object
const dateTime = Temporal.PlainDateTime.from("2026-05-17T14:30:00");

The T is a literal to separate the date from the time.

What You Should Learn

  • How to use JavaScript Temporal.PlainDateTime
  • How to work with date and time without a time zone
  • How to add and subtract dates
  • How to compare dates safely

PlainDateTime is useful when you need both date and time, but not time zone.

How to Create a PlainDateTime Object

An PlainDateTime object can be created in several different ways:

FromCode
Constructor (new)new Temporal.PlainDateTime()
ISO StringTemporal.PlainDateTime.from()
Now (current time)Temporal.Now.plainDateTimeISO()

Create a PlainDateTime with new

You can create a PlainDateTime object using the new constructor.

The constructor takes parameters like year, month, day, hours, and minutes.

Example

// Create a PlainDateTime object
const date = new Temporal.PlainDateTime(2026, 5, 17, 14, 30);

In Temporal objects, months start at 1.

In the legacy Date object, months start at 0.

Create a PlainDateTime from a String

You can create a PlainDateTime object from an ISO 8601 / RFC 9557 string .

Example

// Create a PlainDateTime object
const dateTime = Temporal.PlainDateTime.from("2026-05-17T10:00:00");

The T Between Date and Time?

The T is a literal to separate the date from the time.

You should read it as an abbreviation for Time .

It is the separator required by the ISO 8601 format .

Create a PlainDateTime from Now

You can create a PlainDateTime object from current time.

Example

const now = Temporal.Now.plainDateTimeISO();

Add or Subtract PlainDateTime

You can safely add or subtract time.

The original value does not change.

Example

// Create a PlainDateTime object
const date = Temporal.PlainDateTime.from("2026-05-17T14:30:00");
// Add and subtract time
const earlier = dateTime.subtract({ minutes: 30 });
const later = dateTime.add({ hours: 2 });

When to Use PlainDateTime

  • Applications where time zone conversion is not required.
  • Local event scheduling.
  • Appointments without international time zone handling.
  • Forms that collect date and time.

Compare PlainDateTime Values

You can compare PlaneDateTime values using the equals() method.

Example

const d1 = Temporal.PlainDateTime.from("2026-05-17T14:30:00");
const d2 = Temporal.PlainDateTime.from("2026-05-17T14:30:00");
let result = d1.equals(d2)

Most (*) temporal objects have their own equals() method :

  • instant .equals( instant )
  • plaindate .equals( plaindate )
  • plaintime .equals( plaintime )
  • plainyearmonth .equals( plainyearmonth )
  • plainmonthday .equals( plainmonthday )
  • plaindateTime .equals( plaindatetime )
  • zoneddateTime .equals( zoneddtatime )

(*) Duration has not.

Learn More

JavaScript Temporal Compare

Convert to ZonedDateTime

A PlainDateTime object does not include time zone information.

You can convert it to a ZonedDateTime if needed.

Example

const dateTime = Temporal.PlainDateTime.from("2026-05-17T10:00:00");
const zoned = dateTime.toZonedDateTime("Europe/Oslo");

Compare PlainDateTime with Other Types

TypeMeaning
InstantExact Moment in UTC time
PlainDateTimePlaind Date and Time (No Timezone)
ZonedDateTimeLocal Date and Time (+ Time Zone)

Temporal.PlainDateTime Methods

ConstructingDescription
from()Creates a PlainDateTime object from an object or a string
newCreates a PlainDateTime object from parameters
Arithmetic
add()Returns a PlainDateTime with a duration added
subtract()Returns a PlainDateTime with a duration subtracted
round()Returns a PlainDateTime rounded to a given unit
Comparing
compare()Returns -1, 0, or 1 from comparing two dates
equals()Returns true if two PlainDateTime objects are identical
since()Returns the difference from another PlainDateTime
until()Returns the difference until another PlainDateTime
Converting
toPlainDate()Returns a PlainDate object with the date from this PlainDateTime
toPlainTime()Returns a PlainTime object with the time from this PlainDateTime
toZonedDateTime()Returns a ZonedDatetime object with this PlainDateTime in a time zone
with()Returns a PlainDateTime with specified fields modified
withCalendar()Returns a PlainDateTime with a different calendar system
withPlainTime()Returns a PlainDateTime with the time part replaced by a new time
Formatting
toJSON()Returns an RFC 9557 format string for JSON serialization
toLocaleString()Returns a language-sensitive representation of the date
toString()Returns an RFC 9557 format string representation of the date
valueOf()Throws an error to prevents temporals from being converted to primitives

Temporal.PlainDateTime Properties

The Temporal.PlainDateTime object has 22 properties of date information.

Display all PlainDateTime PropertiesExample

const date = new Temporal.PlainDateTime(2026, 5, 1, 14, 30);
PropertyDescription
calendarIDCalendar system identifier ("iso8601")
dayThe day as an integer (1-31)
dayOfWeekThe day of the week as an integer (1 = Monday)
dayOfYearThe ordinal day of the year
daysInMonthThe total number of days in that month
daysInWeekThe total number of days in that week
daysInYearThe total number of days in that year
eraThe era name of the calendar, if applicable ("gregory")
eraYearThe year within the era, if applicable
hourThe hour as an integer (0-23
inLeapYearA boolean indicating if the date falls in a leap year
microsecondThe microsecond as an integer (0-999)
millisecondThe millisecond as an integer (0-999)
minuteThe minute as an integer (0-59)
monthThe month as an integer (1-12)
monthCodeA calendar-specific string code for the month ("M01")
monthsInYearThe total number of months in that year
nanosecondThe nanosecond as an integer (0-999)
secondThe second as an integer (0-59)
weekOfYearThe week number within the year
yearThe year as an integer
yearOfWeekThe year that the week belongs to

Previous

JavaScript Display Objects

Next

JavaScript Function apply()