Sikau

JavaScript Applications · Day 32 · about 25 min

Dates and times

Working with the Date object.

What day is it?

Birthdays, deadlines, "posted 3 days ago" — apps need dates. JavaScript's Date object stores a moment in time and can tell you its year, month, day and more.

Making and reading dates

const now = new Date();
console.log(now.getFullYear());

const dashain = new Date(2026, 9, 21);
console.log(dashain.getMonth());
console.log(dashain.getDate());
console.log(dashain.getDay());
console.log(dashain.toLocaleDateString("en-GB"));

The rest of this lesson

  • Doing maths with datesexplain
  • Showing dates to peopleexplain
  • Predict the outputpredict
  • Which month?predict
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap