android - Change Joda DateTime timezone but don't change time -


i using (maybe incorrectly) joda datetime store reminder time in reminders app. when timezone changes on device (because of dst or moving different tz) want able reset reminders use current timezone keep time.

for example: set reminder friday may 15th, @ 15:00. if timezone changes before time, want able recreate reminder friday may 15th @ 15:00 local time.

i have tried use withzoneretainfields haven't been able keep time unchanged:

new datetime(remindertimemillis, datetimezone.forid(previoustimezone)).withzoneretainfields(datetimezone.getdefault()) 

well, method should work:

@test public void change_timezone_of_reminder() {     datetime originalreminderdatetime = localdatetime.parse("2015-05-15t15:00").todatetime(             datetimezone.forid("europe/berlin"));     assertthat(originalreminderdatetime.tostring(), equalto("2015-05-15t15:00:00.000+02:00"));     long remindermillis = originalreminderdatetime.getmillis();     datetime updatedtime = new datetime(remindermillis, datetimezone.forid("europe/berlin"))             .withzoneretainfields(datetimezone.forid("america/new_york"));     assertthat(updatedtime.tolocaldatetime(), equalto(localdatetime.parse("2015-05-15t15:00")));     assertthat(updatedtime.tostring(), equalto("2015-05-15t15:00:00.000-04:00")); } 

so, how evaluating time field not changing?

also, if storing reminder time millis-after-epoch, don't need adjust dst shifts, if you're calculating millis using full timezone ("europe/berlin") rather fixed offset.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -