0

My Spring web app is storing timestamps with time zone in Postgre database. Right now, I'm using Thymeleaf and displaying raw timestamps on frontend. Those timestamps look really bad, so I want to convert them to local date and time.

I know there's an option to convert them right after they're retrieved via repository from the database, but I've been told that there's better way using JavaScript. I've searched for a bit, but found no solution so far.

I just need a keyword I can read on. Any leads on how to use JS to convert that?

Maciaz
  • 1,084
  • 1
  • 16
  • 31
  • Have you looked into using moment.js? – chevybow Apr 18 '18 at 18:26
  • The best way to store date/time will be in ISO format. In javascript you can create date/time in ISO format using `toISOString()` – Anurag Singh Bisht Apr 18 '18 at 18:26
  • What do your timestamps look like now? Also, do you want the time to be localized to the client time zone (JavaScript) or the time zone on your server? – musicfuel Apr 18 '18 at 18:30
  • Timestamps look pretty much like that: `2018-04-18T20:31:17.643+02:00`. I want it to be localized to the client time zone. – Maciaz Apr 18 '18 at 18:32
  • If I already have a view with such value rendered, is it even possible to access that value, format it and then reload the view with JS? Or is accessing the DB the only option? – Maciaz Apr 18 '18 at 18:36
  • Writing a parser for a single format isn't difficult, maybe 10 lines of code if you need timezone offset also. There are also a number of good parsing and formatting libraries. Chose one. – RobG Apr 18 '18 at 21:24
  • 1
    Put extra information in the question, don't hide it in comments. – RobG Apr 18 '18 at 21:24

0 Answers0