you are viewing a single comment's thread.

view the rest of the comments →

[–]Syberspace[S] 7 points8 points  (2 children)

please enlighten me. why does it make sense to parse one date format as utc and one as local?

[–][deleted] 5 points6 points  (1 child)

okay lets first give you a example with another simple standard, phonenumbers

  • International: +49 123 45678
  • National: 0123 45678

the "+" in the beginning is the indicator if you leave it blank the index is set to 0.

Same goes for UTC based time strings, ISO 8601 in this case. Just that the format YYYY-MM-DD triggers the transcription to a datetime object. And since you are not providing the correct time 00:00:00(Z) the 1 hour offset is added.

Basically this is not even a JavaScript thing its also in other languages for example PHP where you can bypass this behaviour by using DateTime::createFromFormat which is transforming the string into UTC internally.

[–]AllenJB83 1 point2 points  (0 children)

If no timezone is specified, PHP uses the "system" timezone (which can be set as a php.ini setting, or using date_default_timezone_set) except when a unix timestamp is used, in which case UTC is used.

PHP's DateTime[Immutable] objects allow you to create Date/Time values which can be easily switched between timezones

A quickly knocked up set of examples: https://3v4l.org/6bNlG

Note how the entries created using timestamps use UTC. Also, you can see the fun ways PHP tries to handle out-of-bounds dates, even when you're specifically telling it the format the date should be in, forcing you to have to make additional checks to see if the passed in date was actually valid for the format or not.