I have a scenario where in I need to store the date time in which ever timezone it is, rather than converting to local time zone.
For example, I get the date in Europe/Berlin timezone and America/New_York timezone. If my JVM is in Berlin, the datetime from America/New_York is getting converted to Berlin timezone.
I'm using the spring annotation:
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
I know this converts the provided datetime to persist in the localdatetime. But how to avoid that and store the datetime in whatever timezone it is. Is there any other type that does the function?
You have three options here:
PersistentDateTimeAndZone - will persist your DateTime in two separate columns - one for the timestamp (local to the time zone this DateTime's time zone) and one for the time zone IDPersistentDateTimeAndZoneWithOffset - same as above, but the time zone column will hold the time zone offsetPersistentDateTimeAsUtcString - will put everything in one column as follows:
Persist DateTime as a string of three parts:
- the DateTime transformed into UTC time, formatted as such:
yyyy-MM-dd'T'HH:mm:ss.SSS- the underscore symbol (
_)- the id of the DateTime's original time zone (for example
Europe/LondonorUTC)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With