java - How can I figure out the UTC offset using Joda? -
i'd end string in form of -5:00
(if we're in ny, example). what's best way go doing using joda?
not sure if it's best way, here's 1 method:
datetimeformatter dtf = datetimeformat.forpattern("zz"); datetimezone zone; zone = datetimezone.forid("america/los_angeles"); system.out.println(dtf.withzone(zone).print(0)); // outputs -08:00 zone = datetimezone.foroffsethoursminutes(-5, 0); system.out.println(dtf.withzone(zone).print(0)); // outputs -05:00 datetime dt = datetime.now(); system.out.println(dtf.print(dt)); // outputs -05:00 (time-zone dependent)
the example give doesn't include leading 0 on hours, though. if that's you're asking (how exclude leading zero), i'm no help.
Comments
Post a Comment