david blaine
david blaine

Reputation: 5937

Joda Time - Get name of time zone?

My time zone is UTC+03:00. It is stored inside a DateTimeZone object. How do I convert this to its real name, that is, East Africa Time/EAT

Upvotes: 13

Views: 11332

Answers (3)

SteveW
SteveW

Reputation: 397

I have not been able to find anything in JodaTime to give the nice readable name. In my experience, the DateTimeZone.getName() returns the id instead of a more useful name. So I can only get "America/New_York", not "Eastern Standard Time".

And the suggest of TimeZone.getDisplayName seems to assume you are using TimeZone from Java, not Joda. I see no getDisplayName() for JodaTime.

Upvotes: 1

Jeevan
Jeevan

Reputation: 8772

With joda, one can get Time-zone abbreviation or name as below

DateTimeZone dz = DateTimeZone.forID("America/New_York");
String tzid = dz.getShortName(DateTimeUtils.currentTimeMillis());
//tzid will be 'EST'

String longerTimeZoneName = dz.getName(DateTimeUtils.currentTimeMillis());
//longerTimeZoneName  will be 'Eastern Standard Time'

Upvotes: 11

Ilya
Ilya

Reputation: 29693

Use method TimeZone#getDisplayName()

DateTimeZone tz = //...  
tz.toTimeZone().getDisplayName();

Upvotes: 5

Related Questions