Dates
new Date() creates the current moment. You can also build one from parts or a string. Methods such as getFullYear, getMonth (0 to 11), getDate and getDay read the pieces. Months start at 0, which surprises many people.
Use toLocaleDateString for a friendly format. Subtracting two dates gives milliseconds.
Example
const d = new Date(2026, 0, 15);
console.log(d.getFullYear(), d.getMonth(), d.getDate());
console.log(d.toLocaleDateString("en-GB", { day: "numeric", month: "long", year: "numeric" }));
const start = new Date("2026-01-01");
const end = new Date("2026-01-31");
console.log((end - start) / (1000 * 60 * 60 * 24));Exercise
Create the current date and time.
const now = new ();
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.