Sometimes, we want to get the beginning and end of the day with moment and JavaScript.
In this article, we’ll look at how to get the beginning and end of the day with moment and JavaScript.
How to get the beginning and end of the day with moment and JavaScript?
To get the beginning and end of the day with moment and JavaScript, we can use the startOf
and endOf
methods.
For instance, we write
const now = moment();
console.log("start", now.startOf("day").toString());
console.log("end", now.endOf("day").toString());
to create a moment object with the current date time with moment()
.
Then we call now.startOf
with 'day'
to return a moment object with the start of the current day.
We call now.endOf
with 'day'
to return a moment object with the start of the current day.
Conclusion
To get the beginning and end of the day with moment and JavaScript, we can use the startOf
and endOf
methods.