Lesson 17 of 55
javascriptWorking with Dates – `Date` object & Intl
8 mins
Course progress31%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 17 of 55
javascript8 mins
Keep these ideas in mind as you work through the lesson.
Create a date:
const now = new Date();
const specific = new Date('2024-02-27T10:00:00Z');
Common methods:
getFullYear(), getMonth(), getDate() – retrieve parts.toISOString(), toLocaleString() – format output.Intl.DateTimeFormat for locale‑aware formatting:
const fmt = new Intl.DateTimeFormat('de-DE', { dateStyle:'short', timeStyle:'short' });
console.log(fmt.format(now)); // 27.02.24, 11:00
const end = new Date('2024-12-31');
setInterval(()=>{
const diff = end - new Date();
if(diff<=0){ clearInterval(this); console.log('Happy New Year!'); }
else{ console.log(Math.floor(diff/1000)+' seconds left'); }
},1000);