Good Code
The good version makes locale and time zone part of the formatting decision, so the same timestamp can be displayed consistently for the intended audience.
Lesson 10
Format dates with explicit locale and time zone choices instead of manual date math.
function formatReleaseDate(isoDate, locale, timeZone) {
// Locale and time zone are explicit formatting inputs.
const formatter = new Intl.DateTimeFormat(locale, {
dateStyle: "medium",
timeZone,
});
return formatter.format(new Date(isoDate));
}
formatReleaseDate("2026-05-24T00:00:00Z", "en-US", "UTC");function formatReleaseDate(dateString) {
// Manual formatting depends on the runtime's local time zone.
const date = new Date(dateString);
return (
date.getMonth() + 1 + "/" +
date.getDate() + "/" +
date.getFullYear()
);
}The good version makes locale and time zone part of the formatting decision, so the same timestamp can be displayed consistently for the intended audience.
The bad version formats by hand using the runtime's local time zone, which can shift the displayed day for users in different regions.