0

I am trying to take some dates coming in as yyyy-mm-dd format and convert them into a Javascript date object. I am using new Date() to do so. It converts it "sucessfully" but 1 day behind the date inputted yyyy-mm-dd format. For example 2019-04-19 get returned as Thu Apr 18 2019 20:00:00 GMT-0400 (Eastern Daylight Time). Is there something i am missing here?

new Date('2019-04-19')

Bobbygllh
  • 132
  • 10
  • 1
    It's a time zone issue. The given date is interpreted by default as a UTC timestamp, so if you're some hours behind UTC you get the previous day. You should not try to make dates from anything other than ISO timestamps unless you're using a library like Moment. – Pointy Apr 19 '19 at 20:30
  • ECMA-262 requires "yyyy-mm-dd" to be parsed as UTC, which is different to ISO 8601 where it's parsed as local. – RobG Apr 20 '19 at 03:09
  • 1
    @Pointy—that is an "ISO timestamp", but the [*TC39 decided*](https://github.com/tc39/ecma262/issues/87) (incorrectly in my view) not to follow ISO 8601 when parsing date only forms. – RobG Apr 20 '19 at 03:11

0 Answers0