Sometimes, we want to get tomorrow, today and yesterday with moment.js and JavaScript.
In this article, we’ll look at how to get tomorrow, today and yesterday with moment.js and JavaScript.
How to get tomorrow, today and yesterday with moment.js and JavaScript?
To get tomorrow, today and yesterday with moment.js and JavaScript, we can use the add method.
For instance, we write
let today = moment();
let tomorrow = moment().add(1, "days");
let yesterday = moment().add(-1, "days");
to get today’s date as a moment object with
let today = moment();
We call add with 1 and 'days' on the moment object for the current date time to get tomorrow’s date.
And we call add with -1 and 'days' on the moment object for the current date time to get yesterday’s date.