1
b2plane
178d

Lost about 4 days debugging bug about date conversion between frontend to backend as an api request.

This shit is mad fucking annoying

The date format was always wrong.

So i gotta ask. Is it better to always have date fields as a Long which contains just a huge number that represents a timestamp, and that way whenever i want to see what date it is i would have to convert it every time on both frontend and backend from timestamp into LocalDateTime, or is it better to keep it as Date/LocalDateTime and not string/long, and that way risk fucking up the date format?

How is it done in real world projects? Whats the right way to do it and why?

Comments
  • 3
    Backend should send and receive in UTC. The format doesn‘t really matter but I recommend iso 8601 because well, it‘s a standard.

    Frontend should store in UTC as well and only convert it to local time when it is presented to the user, like as a text in UI. Take the region info from the UI system to convert to local time.
  • 0
    every component handling dates should _include timezone information_

    and it should _only_ be stored as something else than a native datetime+timezone when being rendered.
  • 3
    UTC timestamps.

    Convert to human readable with timezone just in time (at the very last possible chance).

    Date and time are one of those awful programming things everyone winds up discovering. Check out Tom Scott rambling on about it on YouTube.
Add Comment