0Pricing
JavaScript Academy · Lesson

Time Zones and UTC

Handle UTC and local time correctly.

Local Versus UTC

A date stores one absolute moment, but it can be read in local time or in UTC, the global reference time. The getters come in both flavors.

const d = new Date(Date.UTC(2024, 0, 15, 12, 0, 0))
console.log(d.getUTCHours())

UTC Getters

Methods prefixed with UTC, like getUTCFullYear and getUTCHours, read date components in the UTC zone regardless of the machine.

const d = new Date(Date.UTC(2024, 5, 15, 8, 30, 0))
console.log(d.getUTCFullYear())
console.log(d.getUTCHours())
console.log(d.getUTCMinutes())

All lessons in this course

  1. Creating and Reading Dates
  2. Timestamps and Date Math
  3. Formatting Dates
  4. Time Zones and UTC
← Back to JavaScript Academy