0

I have an example below of code that getting the date and adding certain days. But the result I got from log is like these 1507824000000.

  var endDate = new Date('10/03/2017');
  var numOfDays = 10;
  console.log(endDate.setDate(endDate.getDate() + numOfDays ));
Marksmanship
  • 169
  • 1
  • 11
  • 2
    That'll be a Unix timestamp. 1507824000000 is October 12, 2017 @ 4pm UTC. – ceejayoz Oct 03 '17 at 02:21
  • 1
    As indicated in [`.setDate()` documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate), the method returns a milliseconds value, and updates the date object it was called on. Use `console.log(endDate)` *after* calling `.setDate()` and you'll see a date. – nnnnnn Oct 03 '17 at 02:23
  • Okay thanks for the reply I get it now. I had to convert it. – Marksmanship Oct 03 '17 at 02:30

1 Answers1

0

If you want something to see your 10 days added, you can try the following :

var endDate = new Date('10/03/2017');
var numOfDays = 10;
endDate.setDate(endDate.getDate() + numOfDays); 

var dd = endDate.getDate();
var mm = endDate.getMonth() + 1;
var y = endDate.getFullYear();

var yourNewDate = dd + '/'+ mm + '/'+ y;
console.log(yourNewDate)
Rose
  • 2,619
  • 4
  • 20
  • 27