Modern JavaScript and a project · Lesson 43 of 45
Dates and localised formatting
Date, and showing dates, numbers and money in Arabic and English.
7 minutes2 games
new Date() gives the current time; new Date(2026, 0, 15) builds a date (months start at 0: January is 0!). To display dates nicely in any language, use Intl.
JavaScript
const exam = new Date(2026, 11, 20, 10, 30)
console.log(exam.getFullYear(), exam.getMonth() + 1, exam.getDate())
const opts = { weekday: "long", day: "numeric", month: "long", year: "numeric" }
console.log(new Intl.DateTimeFormat("en-US", opts).format(exam))
console.log(new Intl.DateTimeFormat("ar-EG", opts).format(exam))
const days = Math.ceil((exam - new Date(2026, 10, 30)) / (1000 * 60 * 60 * 24))
console.log(days, "days to go")
console.log(new Intl.NumberFormat("ar-EG", { style: "currency", currency: "EGP" }).format(1499.5))
console.log(new Intl.NumberFormat("en-US").format(1234567.891))What's the output?
const d = new Date(2026, 0, 31) console.log(d.getMonth())
What will this code print?
Exercise
Print the number of days between 1 and 31 March 2026 in UTC (30) so daylight-saving changes do not alter the result.
Expected output: 30
JavaScript
const start = new Date(Date.UTC(2026, 2, 1)) const end = new Date(Date.UTC(2026, 2, 31))
Learn more from
Played 0 of 2 games
Sign in to save your progress and earn XP.