JS Temporal PlainDateTime
Date and Time Without Time Zone
What You Will 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
Note
A Temporal.PlainDateTime represents a date and time without a time zone.
It is useful when you need both date and time, but not time zone calculations.
Create a PlainDateTime
You can create a PlainDateTime object from a string.
Example
// Create a PlainDateTime object
const dateTime = Temporal.PlainDateTime.from("2026-05-17T10:00:00");
Try it Yourself »
You can also create a PlainDateTime object using numeric values.
Example
// Create a PlainDateTime object
const dateTime = new Temporal.PlainDateTime(2026, 5, 17, 10, 0);
Try it Yourself »
Note
In a Temporal object, months start at 1.
In the legasy Date object, months start at 0.
Get the Current Date and Time
Use Temporal.Now.plainDateTimeISO() to get the current date and time.
Combine Date and Time
You can combine PlainDate and PlainTime to create a PlainDateTime.
Example
// Create a PlainDate object
const date = Temporal.PlainDate.from("2026-05-17");
// Create a PlainTime object
const time = Temporal.PlainTime.from("14:30");
// Convert into a PlainDateTime object
const dateTime = date.toPlainDateTime(time);
Try it Yourself »
Add or Subtract Time
You can safely add or subtract time.
The original value does not change.
Example
const dateTime = Temporal.PlainDateTime.from("2026-05-17T10:00:00");
const earlier = dateTime.subtract({ minutes: 30 });
const later = dateTime.add({ hours: 2 });
Try it Yourself »
Compare PlainDateTime Values
You can use equals().
Example
const a = Temporal.PlainDateTime.from("2026-05-17T10:00:00");
const b = Temporal.PlainDateTime.from("2026-05-17T10:00:00");
Try it Yourself »
Convert to ZonedDateTime
A PlainDateTime 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");
Try it Yourself »
When to Use PlainDateTime
Local event scheduling.
Appointments without international time zone handling.
Forms that collect date and time.
Applications where time zone conversion is not required.
Summary
Temporal.PlainDateTime represents a date and time without time zone information.
It is immutable, easy to compare, and safer than using Date for local date-time values.