Dates, Time & Intl
Navigate the complexities of timezones, the Date object, and the modern Intl API for robust localization without external libraries.
The Date Object
JavaScript's Date object represents a single moment in time. Under the hood, it stores time as the number of milliseconds since the 'Unix Epoch' (January 1, 1970, UTC).
javascript
const now = new Date();
const specific = new Date('2025-12-25T10:00:00Z');
The Timezone Trap
Dates in JavaScript are inherently timezone-agnostic (they just store UTC milliseconds). The confusion arises because methods like .getHours() or .toString() automatically convert that UTC time into the user's *local* timezone.
If you save an event at 10:00 AM in New York, and a user in Tokyo opens their browser, .getHours() will translate that same moment in time to their local evening.
The Intl API
Historically, developers relied on massive libraries like moment.js to format dates. Today, modern browsers have the incredibly powerful Intl.DateTimeFormat built-in.
javascript
const formatter = new Intl.DateTimeFormat('en-GB', {
dateStyle: 'full',
timeStyle: 'short',
timeZone: 'Asia/Tokyo'
});
console.log(formatter.format(now));
With a single native object, you can translate a timestamp into any language and format it for any timezone on Earth.
The Intl Formatter
Select a Locale and a Timezone below. Watch how the exact same JavaScript Date object automatically reshapes itself to fit different cultural standards and global clocks.
dateStyle: 'full',
timeStyle: 'short',
timeZone: 'UTC'
});
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
- A JavaScript
Dateobject stores a single moment in time (UTC milliseconds since 1970). - Methods like
.getHours()automatically convert the UTC time into the user's local timezone. - Use
.toISOString()to generate a safe, universal string for APIs and databases. - Let the
Dateobject handle date math using.setMonth(),.setDate(), etc. - Use the native
Intl.DateTimeFormatAPI for powerful, library-free localization and timezone conversion.
Done with this concept?
Mark it complete to track your progress. No login needed.