Advertisement

Date, Time & Internationalization (Intl API) interview questions and answers

10 Date, Time & Internationalization (Intl API) interview questions for JavaScript roles, each with a model answer, examples and likely follow-ups.

10 questions
Advertisement

10 questions

Q1 Beginner Save

How do you create a Date object representing the current moment?

new Date() with no arguments creates a Date object set to the current date and time, based on the system clock, represented internally as milliseconds since the Unix epoch (Jan 1, 1970 UTC).
const now = new Date();
console.log(now.getTime()); // e.g. 1770512400000
Real-world example
Timestamping when a user submits a form, for auditing or sorting purposes.
Likely follow-ups
  • How do you create a Date for a specific known date?
Numbers Math & BigInt
Q2 Beginner Save

Why is Date.parse() considered unreliable for parsing date strings?

Date.parse() (and new Date(string)) behavior for non-ISO formats is implementation-defined, so the same string can parse differently across browsers. Only the ISO 8601 format (e.g. '2026-08-08') is guaranteed to parse consistently.
new Date('2026-08-08');        // reliable, ISO format
new Date('08/08/2026');        // ambiguous across locales/engines
Real-world example
A bug where a date string parsed fine in Chrome but produced Invalid Date in Safari.
Likely follow-ups
  • What library is commonly used to avoid these parsing inconsistencies?
Error Handling
Q3 Intermediate Save

How do you format a date for a specific locale without a library?

Intl.DateTimeFormat lets you format dates according to locale conventions and customizable options (weekday, month style, etc.), without needing an external date library for basic formatting.
const formatter = new Intl.DateTimeFormat('en-GB', { dateStyle: 'long' });
console.log(formatter.format(new Date())); // '8 August 2026'
Real-world example
Displaying order dates in the format users in a specific country expect (DD/MM/YYYY vs MM/DD/YYYY).
Likely follow-ups
  • How would you format just the time portion, not the date?
Design Patterns in JavaScript
Q4 Intermediate Save

How do you calculate the difference between two dates in days?

Subtracting two Date objects (or calling getTime() on each) yields the difference in milliseconds; divide by the number of milliseconds in a day (1000*60*60*24) to get whole days.
const start = new Date('2026-08-01');
const end = new Date('2026-08-08');
const days = (end - start) / (1000*60*60*24); // 7
Real-world example
Calculating how many days remain until a subscription renews.
Likely follow-ups
  • Why can this calculation be off by an hour around daylight saving time changes?
Numbers Math & BigInt
Q5 Intermediate Save

How do you format numbers and currency for a locale using Intl.NumberFormat?

Intl.NumberFormat handles locale-aware digit grouping, decimal separators, and currency symbols automatically, avoiding manual and error-prone string manipulation.
const price = new Intl.NumberFormat('de-DE', {
  style: 'currency', currency: 'EUR'
}).format(1234.5);
console.log(price); // '1.234,50 €'
Real-world example
Displaying product prices correctly formatted for a user's detected region.
Likely follow-ups
  • How would you format a large number with abbreviations like '1.2K'?
Types & Coercion
Q6 Advanced Save

Why is manually working with time zones using the Date object error-prone?

The built-in Date object always represents a single instant in time and only exposes it in either UTC or the *local system's* time zone — there's no built-in way to reliably format a date in an arbitrary, different time zone without extra options or a library.
// Formatting in a specific, non-local zone requires Intl:
new Intl.DateTimeFormat('en-US', {
  timeZone: 'America/New_York', timeStyle: 'short'
}).format(new Date());
Real-world example
Showing a meeting time correctly in both the organizer's and an attendee's time zones.
Likely follow-ups
  • What does the newer Temporal API aim to fix about Date's time zone handling?
Error Handling
Q7 Advanced Save

How do you sort an array of strings correctly for a given language using Intl.Collator?

Default string comparison (< and >) uses UTF-16 code point order, which doesn't match human-expected alphabetical order for many languages (accents, special characters). Intl.Collator provides locale-aware, linguistically correct sorting.
const collator = new Intl.Collator('sv');
['ö', 'z', 'a'].sort(collator.compare); // locale-correct Swedish order
Real-world example
Sorting a list of customer names correctly for users in different countries, respecting local alphabetization rules.
Likely follow-ups
  • How does Intl.Collator handle case-insensitive sorting?
Arrays & Array Methods
Q8 Advanced Save

What is the Temporal API and what problem does it solve?

Temporal is a modern proposal/API for date and time handling designed to replace the flawed, mutable Date object with immutable, explicit types (PlainDate, ZonedDateTime, Duration, etc.) that handle time zones and calendars correctly by design.
// Temporal (where available):
const date = Temporal.PlainDate.from('2026-08-08');
const later = date.add({ days: 7 });
console.log(later.toString()); // '2026-08-15'
Real-world example
Building a scheduling app where date math needs to be reliably correct across time zones and calendar edge cases.
Likely follow-ups
  • Why has adoption of Temporal been gradual across browsers?
Design Patterns in JavaScript
Q9 Advanced Save

How do you get a relative time string like '3 days ago' using built-in APIs?

Intl.RelativeTimeFormat generates locale-correct relative phrases from a numeric offset and unit, without manually building strings like 'X days ago'.
const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
console.log(rtf.format(-3, 'day')); // '3 days ago'
console.log(rtf.format(1, 'day'));  // 'tomorrow'
Real-world example
Showing 'Posted 2 hours ago' style timestamps in a social feed or comment section.
Likely follow-ups
  • How would you compute the numeric offset needed for RelativeTimeFormat from two Date objects?
Numbers Math & BigInt
Q10 Advanced Save

Why does new Date(2026, 7, 8) represent August 8th, not July 8th?

The Date constructor's month argument is zero-indexed (0 = January, 11 = December) for historical reasons, so month 7 means the 8th month, August — a very common source of off-by-one date bugs.
const d = new Date(2026, 7, 8);
console.log(d.getMonth()); // 7
console.log(d.toDateString()); // 'Sat Aug 08 2026'
Real-world example
A recurring bug class where developers pass the human month number directly and get the wrong month.
Likely follow-ups
  • Does Intl.DateTimeFormat or Temporal also use zero-indexed months?
Error Handling