setDate() returns number 1603240915215 instead of a date

前端 未结 2 1542
萌比男神i
萌比男神i 2021-01-27 21:08
const date = new Date(\'August 19, 2020 23:15:30\');
const event = new Date();
  console.log(`event.setDate(date.getDate() + 1));

this code is supposed

2条回答
  •  轮回少年
    2021-01-27 21:22

    .setDate return milliseconds. You want to access the dateInstance instead:

    const day = new Date('August 19, 2020 23:15:30'), nextDay = new Date();
    nextDay.setDate(day.getDate()+1); console.log(nextDay.toString());

提交回复
热议问题