Skip to content Skip to sidebar Skip to footer

Get Three-letter Short Timezone Name (as Opposed To Four-letter)?

I've written an Android app that needs the short timezone name in which the handset is currently located. I'm using the following code: String timeZone = Calendar.getInstance().get

Solution 1:

I'm sorry, but you're probably stuck maintaining a mapping. The three-character are actually the older, not more modern version. From the classdocs:

    For compatibility with JDK 1.1.x, some other three-letter time zone IDs (such as "PST", "CTT", "AST") are also supported. However, their use is deprecated because the same abbreviation is often used for multiple time zones (for example, "CST" could be U.S. "Central Standard Time" and "China Standard Time"), and the Java platform can then only recognize one of them.

If it were my problem, I'd get the list my third-party system supports and map it.

Solution 2:

You could just use SimpleDateFormat to print the time zone in three letters or full name. For example:

DateFormatgetTimeZoneShort=newSimpleDateFormat("z", Locale.US);
StringtimeZoneShort= getTimeZoneShort.format(Calendar.getInstance().getTime());

DateFormatgetTimeZoneLong=newSimpleDateFormat("zzzz", Locale.US);
StringtimeZoneLong= getTimeZoneLong.format(Calendar.getInstance().getTime());

Post a Comment for "Get Three-letter Short Timezone Name (as Opposed To Four-letter)?"