.setHours(0,0,0,0) with moment.js
JavascriptMomentjsJavascript 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
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")