JavaScript Dates

Create, read and format dates.

✍️ 3 exercises + code challenge in this lesson

The Date object works with dates and times.

  • new Date(): now.
  • new Date(2026, 9, 22): year, month (0 = January!), day.
  • new Date("2026-10-22"): from an ISO string.
  • Get parts: getFullYear(), getMonth(), getDate(), getDay(), getHours().
  • Format: toLocaleDateString(), toISOString(), Intl.DateTimeFormat.

Key Takeaways: JavaScript Dates

Mastering JavaScript Dates helps you write clean and reliable JavaScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

JavaScript Dates Code Example

JavaScript
<pre id="out"></pre>
<script>
const log = (...a) => document.getElementById("out").textContent += a.join(" ") + "\n";
const now = new Date();
log("Now:", now.toLocaleString());

const launch = new Date(2026, 11, 31);
log("Launch:", launch.toDateString());

const days = Math.ceil((launch - now) / (1000 * 60 * 60 * 24));
log("Days until launch:", days);

log(now.toLocaleDateString("en-GB", { weekday: "long", day: "numeric", month: "long", year: "numeric" }));
log("ISO:", now.toISOString());
</script>
Free sign-in required · Google login available

JavaScript Dates Practice Exercises

Check what you learned in “JavaScript Dates”.

/ 3 solved
Fill in the blank

Create a Date object for the current moment.

const now = ;
✓ Correct! Not quite. Try again.
Multiple choice

In new Date(2026, 0, 15), which month is 0?

✓ Correct! Not quite. Try again.
Code challenge

Create the date 15 August 2026 and log its year.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services