java/android - consistent way 3-letter abbreviation for TimeZone

GJain :

How can I get three letter abbreviations in Java for a TimeZone

For eg: TimeZone.getTimeZone("Pacific/Auckland").getDisplayName gives me:

GMT+12

but I want NZST or NZDT.

Is it possible?

Amit K. Saha :

Use Joda-Time

DateTimeZone dz = DateTimeZone.forID("Pacific/Auckland");
String timezone = dz.getNameKey(DateTimeUtils.currentTimeMillis()); // NZST

In your build.gradle add -

implementation 'joda-time:joda-time:2.10'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=80335&siteId=1