15

That’s how you should format a date in JS/TS!

Comments
  • 11
    any date format other than ISO should be abhorred and killed with fire.
  • 0
    What is this, code bowling?
  • 3
    @ryios That was sarcastic 😅

    This piece of code is coming from a coworker 🙂
  • 5
    @TechTech0 having lived in both US and UK the day month, month day thing causes so much hassle, ISO ftw

    I set every date format to ISO now
  • 1
    Wait... ddMMyyyy, that's the best one
  • 2
    @ryios your shitty peace of code doesn’t even add the slashes. Dude holy fuck. You’re fired.
  • 4
    @ryios

    MMddYYYY... that's illegal.

    I would use

    Date(isoDateString).toLocaleDateString(<preferred locale>, {year: 'numeric', month: 'long', day: 'numeric'})

    Resulting in long-formatted "19 April 2019".

    Why?

    For machines, there are only 2 valid formats in my opinion: ISO and Unix.

    For humans, fuck off with this dash vs slash and month-numbering-in-the-wrong place shit. Again, only 2 valid formats: Readable ("19 April 2019") and Relative ("Today" or "In 3 months").

    What I usually do is the human thing for display, with an ISO date as a tooltip.
  • 0
    @bittersweet For humans, ISO8601* is by far the best. I hate the other formats, they are so much harder to read. And please don't use that relative garbage. I hate it when it says "1 year ago".

    *It does not really matter if there is a T or a space in the middle. ISO8601 requires a T but i don't care.
  • 0
    @happygimp0 if you dont care about timezones you'll get angry stupid users directly/indirectly breathing over your neck.

    @bittersweet is absolutely correct.
  • 0
    @bioDan I don't understand what this has to do with timezones, you can display IS8601 with or without timezone information.
  • 1
    No return types?
  • 1
    No docstrings?
  • 1
    @yehaaw 😅
    I had to explain to that guy, that we must avoid using ‘any’, otherwise TS is useless …
Add Comment