Just like this: moment(). subtract(1, 'days') . It will give you the previous day with the same exact current time that is on your local pc.
However, Moment. js has too many drawbacks compared to modern date and time libraries. Its API is not immutable, it is large and it doesn't support tree shaking. Even the Moment team discourages to use their library in new projects.
to create the tomorrow variable that's set to a moment object with today's date. Then we call add with -1 and 'days' to subtract one day to today. And then we call format with 'YYYY-MM-DD' to format the date to YYYY-MM-DD format.
Just like this: moment().subtract(1, 'days')
. It will give you the previous day with the same exact current time that is on your local pc.
Also :
moment().subtract(1, 'day')
It will give you the previous day with the same exact current time that is on your local pc.
When we get yesterday's date, there are three possibilties
1. Get yesterday date with current timing
moment().subtract(1, 'days').toString()
2. Get yesterday date with start of the day
moment().subtract(1, 'days').startOf('day').toString()
3. Get yesterday date with end of the day
moment().subtract(1, 'days').endOf('day').toString()
moment().add(-1, 'days');
You can find more information in the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With