What is the most recommended way to store time in PostgreSQL using Java?

Viewed 88061

I'm storing two dates in the PostgreSQL database. First, is the data of visit of a webpage, and the second date is the date of last modification of the webpage(this is get as a long).

I have some doubts what is the best strategy to store these values.

I only need day/month/year and hour:seconds and this will only for statistical proposes.

So, some doubts:

  • is best store as long and convert on recover of information or store in the data format above?
  • is best set the date of visit on the software or in the insertion in the database?
  • in Java, how are the best classes to handle dates?
3 Answers

I had used java.util.Date in our code to store Date in arguments of my query. I was using Spring JPA and using @Query annotations. The implementation worked.

Related