I am facing problem to format the output as days/mon/years i.e ( 25/08/2019) when I add 5 days with the current date in momentjs.
console.log( moment().add(5, 'days').calendar());
Output:
Sunday at 8:30 PM
But when I add 10 days i.e:
console.log( moment().add(10, 'days').calendar());
Output:
08/30/2019
I need the output for
moment().add(5, 'days').calendar()
as
25/08/2019
I will highly appreciate your help.
Use format method of moment js
moment().add(5, 'days').format('DD/MM/YYYY')
The moment.calendar documentation states that:
Calendar will format a date with different strings depending on how close to referenceTime's date (today by default) the date is.
You can use moment().add(5, 'days').format('DD/MM/YYYY') to achieve what you want.
If you still want to use the calendar method, we can see in the documentation that from version 2.10.5 you can pass a format parameter:
moment().add(5, 'days').calendar(null, {
sameDay: '[Today]',
nextDay: '[Tomorrow]',
nextWeek: 'dddd',
lastDay: '[Yesterday]',
lastWeek: '[Last] dddd',
sameElse: 'DD/MM/YYYY'
})
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