Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

Basic JavaScript

JS Tutorial JS Syntax JS Variables JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Objects JS Scope JS Dates JS Temporal  New JS Arrays JS Sets JS Maps JS Iterations JS Math JS RegExp JS Destructuring JS Data Types JS Errors JS Debugging JS Conventions JS References JS 2026 JS Versions

JS HTML

JS HTML DOM JS Events JS Projects New

JS Advanced

JS Functions JS Objects JS Classes JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Windows JS Web APIs JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


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.

Example

const now = Temporal.Now.plainDateTimeISO();
Try it Yourself »

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.


Note

If you need time zone support, read the next chapter:

ZonedDateTime.


Temporal.PlainDateTime Methods

MethodDescription
from()Returns a new PlainDateTime object from another object or a string
toPlainDate()Returns a new PlainDate object
toPlainTime()Returns a new PlainTime object
toZonedDateTime()Returns a new ZonedDatetime object
with()Returns a new PlainDateTime with specified fields modified
withCalendar()Returns a new PlainDateTime with a different calendar system
withPlainTime()Returns a new PlainDateTime the time part replaced by a new time
Arithmetic
add()Returns a new PlainDateTime with a duration added
subtract()Returns a new PlainDateTime with a duration subtracted
round()Returns a new PlainDateTime rounded to a given unit
Comparison
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 date
until()Returns the difference until another date
Formatting
toString()Returns an ISO 8601 string representation
toJSON()Returns an ISO 8601 string for JSON serialization
toLocaleString()Returns a language-sensitive representation of the date
valueOf()Throws a TypeError (prevents temporals from being converted to primitives)

Temporal.PlainDateTime Properties

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

Example

const date = new Temporal.PlainDateTime(2026, 5, 1, 14, 30);
Try it Yourself »
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


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->