2

I'm trying to get the datetime with daylight savings.

alert(new Date());

Gives me Thu Apr 04 2019 12:10:42 GMT+1100 (Australian Eastern Daylight Time)

alert(new Date(2019,4,4)); 

Gives me Sat May 04 2019 00:00:00 GMT+1000 (Australian Eastern Standard Time)

Why the first result is correct and the second result is incorrect given that, today's date is actually 2019/04/04.

Also the second result does not considers the Daylight savings time.

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
chamara
  • 12,649
  • 32
  • 134
  • 210

1 Answers1

2

It's because months in dates are 0-based (like arrays):

monthIndex
Integer value representing the month, beginning with 0 for January to 11 for December.

Dates in JavaScript

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79