JavaScript lessons learned - 1 minute read
Here’s a lesson I learned the hard way.
When using Date.parse(), use this format: Date.parse(‘03 Nov 2020 00:00:00 +0000’);. Even better, if you don’t need time zone information use Date.UTC (e.g. Date.UTC(2020,11,3,00); so there’s no chance for ambiguity).
**Why?**
This works on some browsers: Date.parse(‘11-03-2020’). It’ll probably work on your desktop. But it *won’t* work consistently, especially on mobile, and it’s a pain to troubleshoot.
When using Date.parse(), use this format: Date.parse(‘03 Nov 2020 00:00:00 +0000’);. Even better, if you don’t need time zone information use Date.UTC (e.g. Date.UTC(2020,11,3,00); so there’s no chance for ambiguity).
**Why?**
This works on some browsers: Date.parse(‘11-03-2020’). It’ll probably work on your desktop. But it *won’t* work consistently, especially on mobile, and it’s a pain to troubleshoot.
Comments
Post a Comment