Create, read and format dates.
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
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