# Beginning of the day in JavaScript

Let's get a date object containing the beginning of the current day:

`let now = new Date(); let date = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);`

As you already know, the parameters of the `Date` object can be omitted from the end. In this case hours, minutes and seconds will be `0`. Let's omit them:

`let now = new Date(); let date = new Date(now.getFullYear(), now.getMonth(), now.getDate());`

But the day cannot be omitted, because if it is omitted, then the value is `1`, but we need the current day. It is also impossible to omit the month without omitting the year according to the rules for working with Date.

It is also impossible to omit the year, month and day at the same time - in this case, the current moment of time will be taken. Why is this bad, because we need the current year, current month and current day? The fact is that we need midnight, that is, hours, minutes and seconds should have the value `0`, and at the current time they will have current values, not midnight.

Determine how many hours have passed between the start of the day and the current time.

← →
↑
en ru