datetime - Java Joda time Daylight savings time -
i having difficulty using jodatime handle daylight savings time.
string time = "3:45-pm"; datetimeformatter formatter = datetimeformat.forpattern("kk:mm-a"); datetime dt = formatter.parsedatetime(time).withzone(datetimezone.forid("america/new_york")); dt = dt.todatetime(datetimezone.utc); startdate = startdate.withhourofday(dt.gethourofday()).withminuteofhour(dt.getminuteofhour());
output code snippet ends being:
2015-04-08 16:46:51.952 info 12244 --- [nio-8080-exec-1] values pulled : 03:45-pm 2015-04-08 16:46:51.952 info 12244 --- [nio-8080-exec-1] values pulled : 08:45-pm
currently, time 5 hours off. not handling daylights saving time. how joda time take dls account?
this happens because datetime
object after parsing set date 01-01-1970
. looks expect set today, isn't.
if want time interpreted 3:45 pm today in timezone america/new_york
, this:
string time = "3:45-pm"; datetimeformatter formatter = datetimeformat.forpattern("kk:mm-a") .withzone(datetimezone.forid("america/new_york")); datetime dt = formatter.parsedatetime(time) .withdate(localdate.now()); system.out.println(dt); system.out.println(dt.withzone(datetimezone.utc));
note: need set zone on datetimeformatter
.