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

JavascriptMomentjs

Javascript Problem Overview


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.

Javascript Solutions


Solution 1 - Javascript

Start of Time

moment().startOf('day')

Solution 2 - Javascript

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 3 - Javascript

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

Solution 4 - Javascript

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNeluView Question on Stackoverflow
Solution 1 - JavascriptNeluView Answer on Stackoverflow
Solution 2 - Javascriptnawaz anjumView Answer on Stackoverflow
Solution 3 - JavascriptGrini SoufyaneView Answer on Stackoverflow
Solution 4 - JavascriptvenkateshwarView Answer on Stackoverflow