When you and I created an object with a date
like this: new Date()
, we left the
parentheses empty. In this case, we got the
current time.
However, you can do it differently - pass it
parameters in the format new Date(year, month,
day, hours, minutes, seconds, milliseconds)
and in this case the current time will not
record into the variable date
, but
the one that we specified in the parameters.
In this case, when passing as a parameter,
the countdown of months starts from zero.
Parameters can be omitted from the end. In this case, the missing parameters for milliseconds, seconds and hours are considered equal to zero, and for days - to one. Year and month cannot be omitted.
Let's create an object with a date for a specific point in time:
let date = new Date(2025, 10, 5, 12, 59, 59);
The ability to specify a point in time can be used, for example, to find out the day of the week for a specific date:
let date = new Date(2025, 10, 5); // sets November 5, 2025
let day = date.getDay();
let days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
console.log(days[day]);
Find out what day of the week your birthday was.