We will learn to how to set a Date’s hours, minutes and seconds to 0 using JavaScript in two different ways. This is the most basic skill when working with time (Date objects) in Javascript.
Set a Date’s hours, minutes and seconds to 0 using JavaScript
Using setHours()
This method is not only able to change the hours of the Date object but also to change the seconds and minutes of Date. You can read the syntax and usage of this method here.
Assume you have a Date object, and you want to set its hours, minutes, and seconds to 0 using JavaScript. You should try to set the milliseconds, seconds, minutes, and hours using the setHours() with all arguments equal to zero.
// Create a new Date object whose time is now
let day = new Date()
// Set a Date’s hours, minutes, and seconds to 0, also milliseconds
day.setHours(0,0,0,0)
console.log(day)
Output:
Thu Oct 27 2022 00:00:00 GMT+0700
The example above indicates that we have set a Date’s hours, minutes, and seconds to 0. Additionally, this method will return the time in seconds (epoch Unix time) of that date object after it has changed. For instance, if we print out the value of the method:
// Create a new Date object whose time is now
let day = new Date()
// Set a Date’s hours, minutes, and seconds to 0 also milliseconds and assign the result to variable result
let result = day.setHours(0,0,0,0)
console.log(result)
Output:
1666803600000
In the next section, we are going to introduce you to a fast solution that can help you set the date’s hours, minutes, and seconds to 0 at the same time as you are creating it.
Using new Date()
This new Date() constructor is somehow different from Date() constructor. However, new Date() method is the method that is more used to create a Date() by most programmers than the Date() one.
If you want to set a date 2nd November’s hours, minutes, and seconds to 0 using JavaScript, you can provide those values in the arguments:
// Create a new Date representing 2nd Nov 2025
let day = new Date(2025,10,2,0,0,0,0)
console.log(day)
Output:
Sun Nov 02 2025 00:00:00 GMT+0700
Never forget to subtract 1 to your desired month to get the correct monthIndex (10 is November) since this index begins at 0 for January (not 1 as you may expect).
This method is easy to understand, but it can only be used when you have an idea of what your desired date is. Otherwise, if it is just a Date object in which you don’t know the date, then you can use the first solution instead or read more guides in our tutorial to get the date properties of that Date object.
Summary
We have learned how to set a Date’s hours, minutes and seconds to 0 using JavaScript using two different ways. We hope that you will succeed in achieving the goal using our tutorials. Good luck for you!
Maybe you are interested:
- Remove the Seconds and Milliseconds from a Date i n JavaScript
- Subtract Minutes from a Date in JavaScript
- Get the current year for copyright using javascript

I’m Edward Anderson. My current job is as a programmer. I’m majoring in information technology and 5 years of programming expertise. Python, C, C++, Javascript, Java, HTML, CSS, and R are my strong suits. Let me know if you have any questions about these programming languages.
Name of the university: HCMUT
Major: CS
Programming Languages: Python, C, C++, Javascript, Java, HTML, CSS, R