Javascript Date() returns wrong values

Viewed 56

Hi the date today is 2020 10th of November. So it should look something like this 2020-11-10

Also, the time now is 7:15 AM

When I run this code:

var d1 = new Date()
console.log(d1)

It outputs this

2020-11-09T23:15:16.226Z

Notice how the day and the hour is wrong.

However, if I run these codes:

console.log( d1.getDate() )
console.log( d1.getHour() )

It outputs the correct values. I have no idea what is going on.

Can someone please explain what's the issue? does it has something to do with time zones?

0 Answers
Related