admin管理员组

文章数量:1026912

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 to return a date but its not returnign a date instead it is returning a number 1603240915215

can some one help me to get the date instead of such number?

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 to return a date but its not returnign a date instead it is returning a number 1603240915215

can some one help me to get the date instead of such number?

Share Improve this question edited Nov 14, 2024 at 11:29 Roel 3,0962 gold badges32 silver badges35 bronze badges asked Oct 9, 2020 at 0:50 krunalkrunal 473 silver badges12 bronze badges 1
  • "supposed to return a date but its not returnign a date instead it is returning a number". That's not what the docs say developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – JMadelaine Commented Oct 9, 2020 at 0:57
Add a ment  | 

2 Answers 2

Reset to default 4
const dateObj = new Date(1603240915215);

.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());

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 to return a date but its not returnign a date instead it is returning a number 1603240915215

can some one help me to get the date instead of such number?

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 to return a date but its not returnign a date instead it is returning a number 1603240915215

can some one help me to get the date instead of such number?

Share Improve this question edited Nov 14, 2024 at 11:29 Roel 3,0962 gold badges32 silver badges35 bronze badges asked Oct 9, 2020 at 0:50 krunalkrunal 473 silver badges12 bronze badges 1
  • "supposed to return a date but its not returnign a date instead it is returning a number". That's not what the docs say developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – JMadelaine Commented Oct 9, 2020 at 0:57
Add a ment  | 

2 Answers 2

Reset to default 4
const dateObj = new Date(1603240915215);

.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());

本文标签: javascriptsetDate() returns number 1603240915215 instead of a dateStack Overflow