JavaScript Dates
A Date object holds one moment in time. Code can build a date for a fixed moment or for the current moment.
Building from parts
The parts are the year, the month, and the day. The month counts from 0, so 9 stands for October.
const day = new Date(2026, 9, 24);
console.log(day.toDateString());A date as ISO text
toISOString writes the date in a standard text format. The time part shows midnight in UTC.
const day = new Date(2026, 9, 24);
console.log(day.toISOString());A date is an object
A Date is an object holding one moment. Its methods turn the moment into text or parts.
const day = new Date(2026, 9, 24);
console.log(typeof day);Example
const start = new Date(2026, 0, 1);
const end = new Date(2026, 11, 31);
console.log(start.toDateString());
console.log(end.toDateString());Key points
- new Date() with no arguments holds the current moment.
- Number parts build a date in local time with no day shift.
- The parts are the year, the month, and the day.
- toDateString shows a date as readable text.
- A Date is an object, and typeof reports object for it.
In this example, two dates mark the first and last days of 2026. The month part 0 stands for January and 11 stands for December. Each date is logged as readable text.
Note
A text date with no time is read as UTC midnight. Number parts avoid that shift.
Try it Yourself
Edit the code, then press Run.
Runs in your browser โ the preview under the editor is the real result. Nothing is sent to a server. The code runner panel (right) does the same with more room.
Exercise
In new Date(2026, 9, 24), which month does the 9 stand for?