1
console.log(new Date(2019, 3, 11, 9))
console.log(new Date(2019, 4, 11, 9))
console.log(new Date(2019, 5, 11, 9))
console.log(new Date(2019, 6, 11, 9))
console.log(new Date(2019, 7, 11, 9))
console.log(new Date(2019, 8, 11, 9))
console.log(new Date(2019, 9, 11, 9))
console.log(new Date(2019, 10, 11, 9))
console.log(new Date(2019, 11, 11, 9))

here is the image for the output --> here is the image that shows the console output for all the time. It should all print out 9, but it displays 8 for some and then 9 for some, can someone please explain what is going on and why it is doing this and how to make it only display 9

it compiles the correct output on google chrome javascript, 
but when running nodejs filemame on terminal that 
output is the image shown above
lepe
  • 24,677
  • 9
  • 99
  • 108
Sultan
  • 91
  • 1
  • 8

1 Answers1

3

The "issue" is that the date is being created in your current timezone, and converted to UTC, and in October 27, 2019 at 01:00 UTC most European Countries turned the clock back by 1 hour. From your profile I can see you're in Dublin.

You can see this is the case, since all dates until October 27 in your code, are showing 8, and the ones after that date, shows 9.

Try using: Date.UTC instead, or better yet try using a library to work with dates, I recommend moment but here's a nice list:

How to initialize a JavaScript Date to a particular time zone

Marcos Casagrande
  • 37,983
  • 8
  • 84
  • 98