java - Convert DateTimeZone to UTC Offset -
given datetimezone
, can name , id of timezone this:
datetimezone timezone = new datetimezone("america/chicago"); // prints "america/chicago" system.out.println(timezone.getid()); // prints "cdt" (since daylight savings time now) system.out.println(timezone.getnamekey(datetimeutils.currenttimemillis())); // prints "central daylight time" system.out.println(timezone.getname(datetimeutils.currenttimemillis()));
all great, timezone utc offset. in case utc offset -05:00
how do joda-time?
a pure joda-solution looks like:
int offsetmillis = datetimezone.forid("america/chicago").getoffset(datetimeutils.currenttimemillis()); datetimezone zone = datetimezone.foroffsetmillis(offsetmillis); string utcoffset = zone.tostring(); system.out.println(utcoffset); // output: -05:00
java jodatime
No comments:
Post a Comment