0
const date = new Date();
const [month, day, year] = [date.getMonth(), date.getDate(), date.getFullYear()];
console.log(month, day, year);

The console is showing one day previous date of mine. Is this the mistake of VS code ?

rioV8
  • 24,506
  • 3
  • 32
  • 49
V V ARJUN
  • 3
  • 3
  • Please show expected result and actual result. ECMAScript months are zero indexed so if `console.log(month, day, year)` is run on 2 Apr 2022 it will return `3, 2, 2022`. – RobG Apr 01 '22 at 20:33
  • have you read the documentation of these functions/classes – rioV8 Apr 01 '22 at 21:40

2 Answers2

0

Check your system's date & time. JavaScript picks date value from system time.

user8115627
  • 108
  • 8
0

day == date.getDate()
but
realMonth != month == date.getMonth()
because month number is given between 0 and 11.

mdn getMonth() return

Ivellios
  • 16
  • 1