re: Formatting dates with JavaScript VIEW POST

re: I know a lot of people look for a generic .format() method on dates, and you could knock something up fairly quickly like this (incomplete): fun...

I code some tests for this article:
I found toLocaleString() method has some effect. e.g. the test not passed if I don't code like this:

let date = new Date(new Date(1555861886106)
.toLocaleString("en-US", { timeZone: "Asia/Shanghai" }));

That's interesting. Yeah I found the locale stuff to be rather unpredictable. Sometimes that's okay but I usually prefer to have more control over it.


Had a second look, seems it's the timeZone that you added that's making the tests pass. I plan on covering timezones in a future article - maybe in the next article about manipulating dates, or maybe I'll save it for its own article since time zones in the browser can be such a headache.

code of conduct - report abuse