bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/JavaScript/Objects, Classes, and Advanced Patterns
JavaScript•Objects, Classes, and Advanced Patterns

JavaScript 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.

  • 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
});

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]");

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

const now = Temporal.Now.zonedDateTimeISO();

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");

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 Javascript Date .

Temporal.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 });

Temporal adjusts automatically if a DST change happens.

ZonedDateTime since()

The since() method calculates the duration between two temporal dates.

Example

const start = Temporal.ZonedDateTime.from( "2026-02-17T09:00:00+01:00[Europe/Oslo]");
const end = Temporal.ZonedDateTime.from( "2026-02-17T17:30:00+01:00[Europe/Oslo]");
const duration = end.since(start);

JavaScript since() and until()

All temporal date objects have their own since() method :

  • plaindate .since( plaindate )
  • plaintime .since( plaintime )
  • plainyearmonth .since( plainyearmonth )
  • plainmonthday .since( plainmonthday )
  • plaindatetime .since( plaindatetime )
  • zoneddatetime .since( zoneddatetime )
  • instant .since( instant )

All temporal objects have their own until() method :

  • plaindate .until( plaindate )
  • plaintime .until( plaintime )
  • plainyearmonth .until( plainyearmonth )
  • plainmonthday .until( plainmonthday )
  • plaindatetime .until( plaindatetime )
  • zoneddatetime .until( zoneddatetime )
  • instant .until( instant )

LearnMore

JavaScript Temporal Since and Until

The with() Method

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

Example

// Create a ZonedDateTime
const date = Temporal.ZonedDateTimr.from("2026-05-17T14:30:00[Europe/Oslo]");
// Replace month and day
const customDate = date.with({ month:12, day:25 });

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");

ZonedDateTime vs PlainDateTime

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

When to Use ZonedDateTime

  • International applications.
  • Booking systems.
  • Flight or travel systems.
  • Applications that must handle DST correctly.
  • Any system where time zones matter.

Temporal ZonedDateTime Methods

ConstructingDescription
newCreates a ZonedDateTime object
from()Creates a ZonedDateTime object from an object or a string
Converting
getTimeZone Transition()Returns a ZonedDateTime object representing the closest instant after or before this instant
toInstant()Returns a Instant object representing this date-time
toPlainDate()Returns a PlainDate object representing this date-time
toPlainDateTime()Returns a PlainDateTime object representing this date-time
toPlainTime()Returns a PlainTime object representing this date-time
startOfDay()Returns a ZonedDateTime representing the first instant of this date
Updating
with()Returns a ZonedDateTime with specified fields modified
withCalendar()Returns a ZonedDateTime with a different calendar system
withPlainTime()Returns a ZonedDateTime the time part replaced by a new time
withTimeZone()Returns a ZonedDateTime representing this date in a new time zone
Arithmetic
add()Returns a ZonedDateTime with a duration added
subtract()Returns a ZonedDateTime with a duration subtracted
round()Returns a ZonedDateTime rounded to a given unit
Comparing
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
toJSON()Returns an ISO 8601 string for JSON serialization
toLocaleString()Returns a language-sensitive representation of the date
toString()Returns an ISO 8601 string representation
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

Display All Properties

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

Previous

JavaScript Objects - Advanced

Next

JavaScript Object Definitions

This chapter

Overview
123

Lessons

539m

Read time

1. JavaScript Objects2. JavaScript Temporal Tutorial3. JavaScript Loops4. JavaScript Advanced Functions5. JavaScript Objects6. JavaScript Temporal Intro7. JavaScript Iterables8. JavaScript Function Definitions9. JavaScript Object Properties10. JavaScript Temporal vs Date11. JavaScript Iterators12. JavaScript Callbacks13. JavaScript Object Methods14. JavaScript Temporal Duration15. JavaScript Generators16. The JavaScript this Keyword17. JavaScript this Keyword18. JavaScript Temporal Instant19. JavaScript Function call()20. JavaScript Display Objects21. JavaScript PlainDateTime22. JavaScript Function apply()23. JavaScript Object Constructors24. JavaScript Temporal PlainDate25. JavaScript Function bind()26. JavaScript PlainYearMonth27. Self-Invoking Functions28. JavaScript PlainMonthDay29. JavaScript Closures30. JavaScript Temporal PlainTime31. JavaScript Objects - Advanced32. JavaScript ZonedDateTime33. JavaScript Object Definitions34. JavaScript Temporal Now35. this in JavaScript Objects36. JS Temporal Arithmetic37. JavaScript Object Iterations38. JS Temporal Differences39. JavaScript Object Accessors40. JS Temporal Compare41. JavaScript Object Management42. JavaScript Temporal Conversion43. JavaScript Object Protection44. Temporal Display Formats45. JavaScript Object Prototypes46. JavaScript Temporal Mistakes47. JavaScript Classes48. Migrate from Date to Temporal49. JavaScript Class Inheritance50. Temporal Standards51. JavaScript Static Methods52. Asynchronous JavaScript53. Asynchronous Programming54. JavaScript Timeouts55. JavaScript Callbacks56. JavaScript Promises57. JavaScript async and await58. JavaScript fetch API59. Debugging Async JavaScript60. JavaScript Modules61. JavaScript Modules Export62. JavaScript Modules Import63. JS Module Namespace64. JavaScript Dynamic Modules65. JavaScript Meta Programming66. JavaScript Reflect67. JavaScript Proxy68. JavaScript Typed Arrays69. Typed Array Methods70. JavaScript ArrayBuffer71. JavaScript DataView72. JavaScript Atomics73. JavaScript HTML DOM Navigation74. JavaScript HTML DOM Elements (Nodes)75. JavaScript HTML DOM Collections76. JavaScript HTML DOM Node Lists77. JavaScript Window - The Browser Object Model78. JavaScript Window Screen79. JavaScript Window Location80. JavaScript Window History81. JavaScript Window Navigator82. JavaScript Popup Boxes83. JavaScript Timing Events84. JavaScript Cookies85. Web APIs - Introduction86. JavaScript Fetch API87. Web Geolocation API88. Web History API89. Pointer Events API90. Web Storage API91. JavaScript Validation API92. Web Workers API93. AJAX Introduction94. AJAX - The XMLHttpRequest Object95. AJAX - XMLHttpRequest96. AJAX - Server Response97. AJAX XML Example98. AJAX PHP Example99. AJAX ASP Example100. AJAX Database Example101. XML Applications102. JavaScript JSON103. JSON Syntax104. JSON vs XML105. JSON Data Types106. JSON.parse()107. JSON.stringify()108. JSON Object Literals109. JSON Array Literals110. JSON PHP111. JSON HTML112. JSONP113. JavaScript / jQuery DOM Selectors114. JavaScript / jQuery HTML Elements115. JavaScript / jQuery CSS Styles116. JavaScript / jQuery HTML DOM117. JavaScript Graphics118. HTML Canvas119. Plotly.js120. Chart.js121. Google Chart122. D3.js123. JavaScript Interview Preparation

On this page

Handle Time Zones CorrectlyWhy ZonedDateTime Is ImportantCreate a ZonedDateTimeGet Current Date and Time with Time ZoneThe ISO 8601 FormatConvert Between Time ZonesAdd Time Safely (DST Safe)ZonedDateTime since()JavaScript since() and until()The with() MethodConvert from InstantZonedDateTime vs PlainDateTimeWhen to Use ZonedDateTimeTemporal ZonedDateTime MethodsTemporal ZonedDateTime Properties