问题
+I have a time tracking app that uses joda DateTime to persist Start/End time with ORM-lite. ORM-lite stores a Joda DateTime as long in database by using its millis. Joda DateTime.getMillis() returns Milliseconds in UTC.
In a few days we switch from daylight-saving time to normal time and I'm not 100% sure if my app will handle this correctly.
To test it I tried to disable the "Automatic date & time (Use network-provided time)" setting of my device and changed the date to one that has normal time. Immediately the text of selected time zone changed from GMT +02:00 to GMT+01:00
I expected that all my time records are one hour earlier (which is actually a fail in a time tracking app) but this wasn't the case. When I set the time zone to e.g. Abu Dhabi GMT +4:00 all my time records are two hours later. This makes sense to me because the entries where created with my default time zone which is GMT +02:00. Why isn’t this the case when I switch from daylight-saving time to normal time?
Cheers, Stefan
回答1:
I guess I had a wrong understanding of how things work.
Sample:
DateTime dtNow = new DateTime(1414479634046);
I thought that "dtNow" would change when switching from normal time to DST. I thought that DST behalves like a separate time zone but this isn't the case. When a DateTime is "restored" from Millis Joda looks at the date and determines if it is normal or DST.
来源:https://stackoverflow.com/questions/26410962/joda-datetime-datetimezone