For event based columns in my database like createdDate I want to store a UTC value.
I am looking for advice if what I am currently doing will solve my problem correctly.
- In postgresql, I will use a timestamp without timezone column
In my scala (similiar to java) code, I will generate a timestamp like:
val currentMs: Long = System.currentTimeMillis new java.sql.Timestamp(currentMs)
I will save that value to the database. All my servers time will be in synch. Now at the database level, I am storing a pure UTC value.
When I retrieve data from the database, I will use Joda-Time which will take the timestamp value from the database and then convert the value to a particular timezone.
Is this the correct way of doing UTC? Am I missing something here because this topic is confusing when you google about it :)
Note: This is a brand new project so I can change things around without issue.
Update
In Step#2, instead of storing the value from a java.sql.Timestamp, what if I just stored the raw currentMs value in a long column. Then in the UI I would convert the unix time to a particular timezone based on the logged in user.
Is this a suitable?