-3

When i run the code bellow, which parses the current date + 7 days, returns huge number on the date variable;

let d = new Date();
let n = d.setDate(d.getDate()+7);
let m = d.getMonth()+1;
let o = d.getFullYear();
let dateOp = n + "/" + m + "/" + o;

dateOp;

// returns "1609772260625/1/2021"
M. M.
  • 11
  • 3
  • 1
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate#Return_value – Bergi Dec 28 '20 at 15:18

1 Answers1

3

From the docs, setDate returns the millisecond difference between the date and the UNIX epoch. So, set the date first, then get the date again:

d.setDate(d.getDate() + 7);
let n = d.getDate();
let m = d.getMonth()+1;
let o = d.getFullYear();
let dateOp = n + "/" + m + "/" + o;

dateOp;
Aplet123
  • 33,825
  • 1
  • 29
  • 55