Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This sounds to me like a really weird YYYY2k problem.

In all seriousness, that is weird. In JavaScript you can't even format a datetime string as far as I've researched, the only way is to import some third party library, otherwise you're concatenating a bunch of function calls to piece together the string you want.



Perhaps not part of ECMA standards, but browsers/node have Intl.DateTimeFormat as the standard library

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...


I believe I've tried that approach before too, but fell short when my boss wanted a specific format that just wasn't doable with that approach. I'm still a little shocked that this isn't something part of ECMA somehow given how many more other programming languages support using time formatted strings.


The whole point of Intl.DateTimeFormat is to intentionally not give you the specific format your boss wants, because your boss is almost certainly wrong about how a date should be formatted in many cases.

You tell the API you want the date and the hours and minutes, but not seconds. It localizes the result correctly for the vistor’s preferred culture (language-country).

If you show someone from England “4/5/2019”, they will think it represents a date 31 days after someone from the USA given the same string.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: