Search code examples
javascriptdateconsole

new Date() is not showing the correct date . Showing one day previous date


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 ?


Solution

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

    mdn getMonth() return