JavaScript · JS Tutorial · Lesson 23
JS Dates
Create, read and format dates.
Date objects are created with new Date(). JavaScript counts months from 0 to 11.
Example
<p id="demo"></p>
<script>
const now = new Date();
const d = new Date(2026, 0, 15, 10, 30); // 15 January 2026, 10:30
let out = "Now: " + now.toDateString() + "<br>";
out += "Custom: " + d.toLocaleDateString("en-GB") + "<br>";
out += "Year: " + d.getFullYear() + ", Month index: " + d.getMonth() + ", Day of week: " + d.getDay() + "<br>";
out += "ISO: " + d.toISOString() + "<br>";
const days = Math.round((d - new Date(2026, 0, 1)) / (1000 * 60 * 60 * 24));
out += "Days since 1 Jan: " + days;
document.getElementById("demo").innerHTML = out;
</script>
| Method | Returns |
|---|---|
| getFullYear() | Year (yyyy) |
| getMonth() | Month (0-11) |
| getDate() | Day of the month (1-31) |
| getDay() | Weekday (0-6, Sunday = 0) |
| getHours() / getMinutes() | Time parts |
| getTime() | Milliseconds since 1 Jan 1970 |
Keep reading “JS Dates”
Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.