'.setHours(0,0,0,0) with moment.js

What is the easiest equivalent of date.setHours(0,0,0,0) when using moment.js?

Basically, if I need a new Date() moment with hours, minutes, seconds, and milliseconds zeroed out.



Solution 1:[1]

Suppose date is the moment object which contains the date having some hours and minutes.

You can use the following code to reset hours, minutes and seconds to 0.

date.utcOffset(0);
date.set({
 hour: 0,
 minute: 0,
 second: 0,
 millisecond: 0,
});

Solution 2:[2]

to set second for example to " 0 " time = moment().second(0);

Solution 3:[3]

If you want in string format, you can use like this: moment().format("YYYY-MM-DD 00:00:00")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Grini Soufyane
Solution 3 venkateshwar