Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joda Time - Get name of time zone?

Tags:

java

jodatime

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

like image 301
david blaine Avatar asked Apr 14 '13 01:04

david blaine


3 Answers

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'
like image 99
Jeevan Avatar answered Sep 27 '22 19:09

Jeevan


Use method TimeZone#getDisplayName()

DateTimeZone tz = //...  
tz.toTimeZone().getDisplayName();
like image 27
Ilya Avatar answered Sep 27 '22 21:09

Ilya


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.

like image 45
SteveW Avatar answered Sep 27 '22 20:09

SteveW