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 ZonedDateTime

Handle Time Zones Correctly

The Temporal.ZonedDateTime object represents a date and time with a time zone.

It is the safest way to handle international date and time calculations.

It prevents common DST bugs and makes time zone conversions clear and predictable.

What You Will Learn:

  • How to use JavaScript Temporal.ZonedDateTime
  • How to handle time zones correctly
  • How to add and subtract date
  • How to avoid DST (Daylight Saving Time) bugs
  • How to convert between time zones safely

Why ZonedDateTime Is Important

Time zones and daylight saving time (DST) can cause serious bugs when using JavaScript Date.

ZonedDateTime solves this by always storing the time zone together with the date and time.

A Temporal.ZonedDateTime is a timezone and calendar-aware date/time object that represents a real time event from the perspective of a particular region on Earth.

The Temporal.ZonedDateTime object is optimized for cases that require a time zone, DST-safe arithmetic and interoperability with an RFC 5545 calendar.

Example: December 7th, 1995 at 3:24 AM in US Pacific time (in Gregorian calendar).


Create a ZonedDateTime

Example

const zonedDate = Temporal.ZonedDateTime.from({
  timeZone: 'Europe/Oslo',
  year: 2026,
  month: 5,
  day: 17,
  hour: 14,
  minute: 30,
  second: 0,
  millisecond: 0,
  microsecond: 0,
  nanosecond: 500
});
Try it Yourself »

You can also create a ZonedDateTime from a string that includes a time zone.

Example

const zdt = Temporal.ZonedDateTime.from
("2026-02-17T14:30:00[Europe/Oslo]");
Try it Yourself »

Note

The time zone name is written inside square brackets.


Get Current Date and Time with Time Zone

The Temporal.Now.zonedDateTimeISO() method returns your system's current date, time, and time zone as a Temporal.ZonedDateTime object.

Example

Get the current date and time from your system's time zone:

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

Note

The current time is returned in ISO 8601 format.


The ISO 8601 Format

  • 2026-03-02: The calendar date (Year-Month-Day).
  • T10:36:00: The time of day (T-Hour:Minute:Second).
  • +01:00: The offset from UTC (Coordinated Universal Time).
  • [Europe/Oslo]: The IANA time zone name, which is the system's local time zone in this case.

Convert Between Time Zones

You can convert a ZonedDateTime to another time zone.

Example

const oslo = Temporal.ZonedDateTime.from
("2026-05-17T14:30:00+01:00[Europe/Oslo]");

const newYork = oslo.withTimeZone("America/New_York");
Try it Yourself »

Note

The exact moment stays the same, but the local clock time changes.


Add Time Safely (DST Safe)

Adding days across a daylight saving change can break with Date.

ZonedDateTime handles this correctly.

Example

const start = Temporal.ZonedDateTime.from
("2026-03-29T00:00:00+01:00[Europe/Oslo]");

const nextDay = start.add({ days: 1 });
Try it Yourself »

Note

Temporal adjusts automatically if a DST change happens.


The width() Method

The width() method creates a new zoned date-time with specified field(s) replaced.

Example

// Create a Temporal object
const date = Temporal.PlainDate.from("2026-05-17");

// Replace month and day
const customDate = date.with({ month:12, day:25 });
Try it Yourself »

Convert from Instant

An Instant represents a UTC moment.

You can convert it to a ZonedDateTime in a specific time zone.

Example

const instant = Temporal.Now.instant();

const zoned = instant.toZonedDateTimeISO("Europe/Oslo");
Try it Yourself »


When to Use ZonedDateTime

  • International applications.

  • Booking systems.

  • Flight or travel systems.

  • Applications that must handle DST correctly.

  • Any system where time zones matter.


ZonedDateTime vs PlainDateTime

Type Includes Time Zone Use Case
PlainDateTime No Local scheduling without conversion
ZonedDateTime Yes International or DST-aware systems

Temporal ZonedDateTime Methods

MethodDescription
from()Returns a new ZonedDateTime object from an object or a string
getTimeZone
Transition()
Returns a ZonedDateTime object representing the closest instant after or before this instant
startOfDay()Returns a ZonedDateTime object representing the first instant of this date
toInstant()Returns a new Instant object representing this date-time
toPlainDate()Returns a new PlainDate object representing this date-time
toPlainDateTime()Returns a new PlainDateTime object representing this date-time
toPlainTime()Returns a new PlainTime object representing this date-time
with()Returns a new ZonedDateTime with specified fields modified
withCalendar()Returns a new ZonedDateTime with a different calendar system
withPlainTime()Returns a new ZonedDateTime the time part replaced by a new time
withTimeZone()Returns a new ZonedDateTime object representing this date-time in the new time zone
Arithmetic
add()Returns a new ZonedDateTime with a duration added
subtract()Returns a new ZonedDateTime with a duration subtracted
round()Returns a new ZonedDateTime rounded to a given unit
Comparison
compare()Returns -1, 0, or 1 from comparing two dates
equals()Returns true if two ZonedDateTime 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 ZonedDateTime Properties

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
epochMillisecondsNumber of milliseconds since Unix epoch
epochNanosecondsNumber of nanoseconds since Unix epoch
eraThe era name of the calendar, if applicable ("gregory")
eraYearThe year within the era, if applicable
hourThe hour as an integer (0-23)
hoursInDayHours in this day in this time zone(0-25)
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)
offsetOffset used to interpret this instant (+HH:mm:ss.sssssssss)
offsetNanosecondsOffset used to interpret this instant in nanoseconds
secondThe second as an integer (0-59)
timeZoneIdTime zone identifier used to interpret this instant
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.

-->