tags:

views:

99

answers:

2

I need to display timezone in the following format in my UI.

(GMT -05:00) Eastern Time(US & Canada).

I tried getting the current time and timezone from calendar. But when i tried to get the display name from timezone it just displays as "Eastern time". I am not getting the format mentioned above. Can anyone help.

Following is my code snippet and i am using JDK 1.4.2.

Calendar c = Calendar.getInstance();
TimeZone tz = c.getTimeZone();
String s = tz.getDisplayName();
A: 

If you're missing the offset, have a look at the getOffset()-method on TimeZone. That should give you enough information to calculate the offset from GMT.

Thomas Lötzer
Nix
+2  A: 

Here's the long getDisplayName() method invocation. Try specifying TimeZone.LONG for the style. The method hasn't changed since Java 1.2

getDisplayName

public final String getDisplayName(boolean daylight, int style, Locale locale)

Returns a name of this time zone suitable for presentation to the user in the default locale. If the display name is not available for the locale, then this method returns a string in the normalized custom ID format.

Parameters:

   daylight - if true, return the daylight savings name.
   style - either LONG or SHORT 
   locale - the locale in which to supply the display name.

Returns:

  the human-readable name of this time zone in the default locale.

If this isn't sufficient, you can always try Joda Time.

Gilbert Le Blanc
I would highly recommend Joda Time anyways.
Erick Robertson