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 TOOLS

Basic JavaScript

JS Tutorial JS Introduction JS Where To JS Output

JS Syntax

JS Syntax JS Statements JS Comments JS Variables JS Let JS Const JS Types

JS Operators

JS Operators

JS If Else

JS If Conditions

JS Loops

JS Loops

JS Strings

JS Strings

JS Numbers

JS Numbers

JS Functions

JS Functions

JS Objects

JS Objects

JS Scope

JS Scope

JS Dates

JS Dates

JS Temporal

JS Temporal  New

JS Arrays

JS Arrays

JS Sets

JS Sets

JS Maps

JS Maps

JS Iterations

JS Loops

JS Math

JS Math

JS RegExp

JS RegExp

JS DataTypes

JS Data Types

JS Errors

JS Errors

JS Debugging

JS Debugging

JS Conventions

JS Style Guide

JS Reference

JS Statements

JS Projects

JS Projects New

JS Versions

JS 2026

JS HTML

JS HTML DOM JS Events

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


JavaScript Temporal vs Date

Learn the differences between Date and Temporal

  • Date is 0-based, Temporal is 1-based
  • Date arithmetic is manual, Temporal is built-in
  • Date mutates values, Temporal does not
  • Date mixes UTC and time zones, Temporal separates them
  • Date can fail in DSD handling, Temporal ca not

Learn why Temporal is the modern alternative to Date.,

JavaScript Date Problems

The JavaScript Date object is old and has several design problems.

These are the most common mistakes developers make when using Date objects:

  • Using the wrong month number because months start at 0.

  • Accidentally changing a date object by calling a mutating method.

  • Parsing unclear strings that behave differently across environments.

  • Mixing local time and UTC values in the same program.

  • Doing math across DST changes and getting unexpected hours.


The JavaScript Date object has been used since 1995.

Temporal is the modern replacement designed to fix many of Date's problems.


Date Months are 0-Based

In the JavaScript Date object, January is month 0 and December is month 11.

Date Example

// May 17, 2026:
let date = new Date(2026, 4, 17)
Try it Yourself »

The Date object is confusing because most people expect January to be month 1.


Temporal Months are 1-Based

In the JavaScript Temporal object, January is month 1 and December is month 12.

This is much more user friendly.

Temporal Example

// May 17, 2026:
let new Temporal.PlainDate(2026, 5, 17)
Try it Yourself »

Date Objects are Mutable

JavaScript Date objects can change.

Date objects are mutable.

Date Example

Date methods can change the original date object:

// Create a Date
let date = new Date("2026-05-17");

// Add 7 days to date
date.setDate(date.getDate() + 7);

// Here the original date is lost
Try it Yourself »

Date Example

Date methods can change other date objects:

// Create a Date
let date1 = new Date("2026-05-17");
// Create a copy
let date2 = date1;

// Add 7 days to date1
date1.setDate(date1.getDate() + 7);

// Here date2 has changed
Try it Yourself »

In the example above, the variables date1 and date2 point to the same object.

So date2 changes when date1 changes.

This can create unexpected results when date values are copied or reused.


Temporal Objects are Immutable

JavaScript Temporal objects cannot change.

Temporal objects are immutable.

Temporal Example

Temporal operations always return a new object (or value).

// Create a Date
let date1 = Temporal.PlainDate.from("2026-05-17");

// Add 7 days
let date2 = date1.add({ days: 7 });

// Here original date1 is kept
Try it Yourself »

Date Parsing is Inconsistent

A string like 2026-05-07 parses as an UTC instant in JavaScript.

JavaScript has been a minefield of different formats, browser quirks and locale surprises.

Date strings can be parsed differently across browsers and environments, and different formats may be interpreted as local time or UTC.

Date Example

const d1 = new Date("2026-05-17");
const d2 = new Date("2026-05-17T00:00:00");
const d3 = new Date("05/17/2026");
const d4 = new Date("May 17 2026");
const d5 = new Date("17 May 2026");
const d6 = new Date(2026, 4, 17);
Try it Yourself »

Temporal PlainDate

Temporal avoids the problems above by defining strict parsing rules for ISO strings.

Temporal.PlainDate is not a timestamp.

It is just 2026-05-17 with no time and no time zone.

Temporal Example

const date = Temporal.PlainDate.from('2026-05-17');
Try it Yourself »

It is safer to avoid unclear formats and use explicit formats when possible.


Date and Time Zone

new Date(2026, 4, 1) creates a timestamp of your local time at midnight.

This means a day can "shift" when you format it to UTC.

Date Example

// Create a Date object
const date = new Date(2026, 4, 1);

// Might be another day in some time zones:
date.toISOString();
Try it Yourself »


Date Mixes Local Time and UTC

A Date object always stores a timestamp, but it can display values as local time or UTC.

This mix can easily cause confusion when converting and comparing dates.

The same moment can look different depending on how it is displayed.

Date Example

let date = new Date();

let time1 = date.toString();
let time2 = date.toUTCString();
Try it Yourself »

Temporal Separates Time and UTC

Temporal uses clear types for time zones.

Temporal.ZonedDateTime always includes a time zone.

Temporal Example

const instant = Temporal.Now.instant();
const local = Temporal.Now.zonedDateTimeISO();
Try it Yourself »

DST Can Break Date Math

Daylight saving time (DST) can cause a day to be 23 or 25 hours long.

This can break calculations that assume every day is exactly 24 hours.

Example

let start = new Date("2026-03-29T00:00:00");
let end = new Date(start.getTime() + 24 * 60 * 60 * 1000);

The result can be off by one hour in time zones with DST changes.


Date Math

Date math often requires manual calculations.

Date Example

const start = new Date("2026-05-01");
const end = new Date("2026-05-17");

const diff = end - start;
Try it Yourself »

Temporal has built-in date arithmetic.

Temporal Example

let start = Temporal.PlainDate.from("2026-05-01");
let end = Temporal.PlainDate.from("2026-05-17");

const diff = start.until(end);
Try it Yourself »

Nanosecond Precision

The Date object uses milliseconds precision.

Temporal offers 1 million times higher nanosecond precision.


Date Mixes Everything

Date mixes everything in one object.

Date (Problem)

const date = new Date(); // date + time + zone

Temporal Uses Clear Types

Temporal objects separates different use cases into different objects.

This makes code easier to read and less error-prone.

ObjectDescription
Temporal.Duration Length of time (days, hours, minutes)
Temporal.Instant Exact moment in UTC time
Temporal.PlainDateTime Plain date and time (no time zone)
Temporal.PlainDatePlain date only (year, month, day)
Temporal.PlainTime Plain time only
Temporal.PlainYearMonthPlain year and month only
Temporal.PlainMonthDayPlain month and day only
Temporal.ZonedDateTimeDate and time with a time zone
Temporal.NowCurrent time (UTC timestamp)

Differences Between Date and Temporal

Feature Date Temporal
Created 1995 2026
Time zone support Limited Built-in
Immutable No Yes
Date-Only Type No Yes
Time-Only Type No Yes
1-Based Months No Yes
DST safe arithmetic No Yes
RFC 5545 iCalendar No Yes
Modern API design No Yes
Precisition Milliseconds Nanoseconds

You may still use JavaScript Date for simple tasks such as getting a quick timestamp.

You may also need it if you support older environments without Temporal.

JavaScript Temporal is safer, clearer, and designed for modern applications.


When to Use Temporal?

  • You need correct time zone handling.

  • You work with international users.

  • You want safe date arithmetic.

  • You want clear and modern code.



×

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.

-->