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.
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.
moment().startOf('day')
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,
});
to set second for example to " 0 "
time = moment().second(0);
If you want in string format, you can use like this: moment().format("YYYY-MM-DD 00:00:00")
© 2022 - 2024 — McMap. All rights reserved.