0

one question. I want to store some time data in room Database. In my application the user can press a Start and Stop Button to save a Start- and a EndTime for doing different tasks. Later he can review all times with a RecyclerView...

Now, the problem is, that i want to keep special anomalies of the different TimeZones. For Example if Summertime (DST) occurs in the TimeZone of the User, then he should have that correct time if he presses the Button and later review the times. But i read that OffsetDateTime does not store such anomalies. Instead ZonedDateTime would be the right one. But if i want to store the times i need to use OffsetDateTime.

What can i do? I guess if i create a ZonedDateTime at the moment the user presses a button, and then i convert it to OffsetDatetime and then back for retrieving Data, the Summertime, or DST, is lost in the converting process?

Anybody can help, please? Searched everything but couldnt see any anwsers.

Thank you.

steeveKA1
  • 13
  • 6
  • My first thought would be to store UTC times in the database and convert to the user’s time zone only when displaying the times. If you don’t want that, you may use `OffsetDateTime.now(ZoneId.systemDefault())`. While the obtained `OffsetDateTime` will not know which time zone it came from, the `now` method will respect the time zone and its anomalies and give you the time at the correct offset for the time of year according to standard time and summer time and other anomalies. For example in my time zone you may get 2023-05-04T12:28+02:00 now and 2023-12-12T23:15+01:00 next winter. – Ole V.V. May 04 '23 at 10:23

0 Answers0