Today's Date Moments.js

0

I am using Moment.js with the following code, and it is to generate the expiration date all month according to the selected date, however when I select today's date, it appears written Today 28/04/2018 , how to fix this error?

for ($i = 0; $i < 12; $i++){
var minhaData = moment(ParcelaVencimento, "YYYY/M/D h:m").add('months', $i);

    ParcelaVencimento1 =  minhaData.calendar();

    var linha = '<tr class="selected" id="linha'+cont+'">    <td> <button type="button" class="btn btn-warning" onclick="apagar('+cont+');"> X </button></td>      <td> <input type="hidden" name="cont[]" value="'+cont+'">'+cont+'</td>   <td> <input type="text" name="ParcelaVencimento1[]" value="'+ParcelaVencimento1+'"></td>  </tr>'

Date

Today at 00:00

05/28/2018

6/28/2018

7/28/2018

    
asked by anonymous 28.04.2018 / 23:08

1 answer

0

Correct is to use the format() method instead of calendar() . Another point to note is that the add() method is getting parameters in a format that has been discontinued instead of% with% use add('months', $i)

Example running

var ParcelaVencimento = '2018-04-01';
for ($i = 0; $i < 12; $i++) {
  var minhaData = moment(ParcelaVencimento).add($i, 'months');
  console.log(minhaData.format('DD/MM/YYYY'))
}
<script src="https://cdn.jsdelivr.net/momentjs/2.14.1/moment-with-locales.min.js"></script>
    
28.04.2018 / 23:36