JavaScript How to add 5 days with current date and format the output in momentjs? days current affairs,days(current date) in db2,days current

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.

Answer:1

Use format method of moment js

moment().add(5, 'days').format('DD/MM/YYYY') 
Answer:2

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'
})
Answer:3

In the JavaScript chaijs testing library it is possible to chain members like this: pm.expect (entry.NAME).to.be.a('string').that.is.not.empty; This question is not about the testing library, but ...

In the JavaScript chaijs testing library it is possible to chain members like this: pm.expect (entry.NAME).to.be.a('string').that.is.not.empty; This question is not about the testing library, but ...

<mat-option class="select-bank-option mat-option ng-star-inserted mat-selected mat-active" role="option" data-cy="selectDKCAD" tabindex="0" id="mat-option-261" aria-disabled="false" aria-selected="...

<mat-option class="select-bank-option mat-option ng-star-inserted mat-selected mat-active" role="option" data-cy="selectDKCAD" tabindex="0" id="mat-option-261" aria-disabled="false" aria-selected="...

I'm stuck on a template/component problem and I couldn't find any answer. I'm trying to move a plain Javascript project to Angular2. In my project, I actually create some elements by inherit from ...

I'm stuck on a template/component problem and I couldn't find any answer. I'm trying to move a plain Javascript project to Angular2. In my project, I actually create some elements by inherit from ...

  1. styled components nested elements
  2. styled-components nested elements

I'm using OpenLayers3 to integrate a map into a website. I added some features representing objects according to their position. I added an overlay containing data on that object when it is clicked on,...

I'm using OpenLayers3 to integrate a map into a website. I added some features representing objects according to their position. I added an overlay containing data on that object when it is clicked on,...