The i18n Cookbook - recipies for a global society

  • java cookbook
  • about the author
Home

Java Cookbook

  • Java Internationalization Cookbook

timezone

Get the display name for a Timezone

Problem:

You want to get a localized display name for a time zone.

Solution:

You can get a display name for a TimeZone in Java very easily by specifying a locale in the getDisplayName method.

 

To get a display name for Canada/Mountain in Japanese:

  • display name
  • timezone
  • Add new comment
  • Read more

Get an array of timezone ids for offset

Problem:

You know what your offset from UTC is and you want to know what timezones are available for that offset

Solution:

The Java TimeZone class uses string ids to retrieve an instance.  You can get a list of all TimeZone ids, but the list is quite large.  Luckily you can narrow the results by specifying an offset from UTC and retrieve only the results with that raw offset.

 

The offset is specified as milliseconds from UTC.  Go figure.

 

  • timezone
  • Add new comment
  • Read more

Get all time zone ids

Problem:

You want to know what time zones are available on your system.

Solution:

Java uses the TimeZone class to handle date/time casting to and from UTC.  A TimeZone is retrieved by specifying a string id.  Most of these ids are Olsen time zone ids.  You can retrieve an array of time zone ids by calling the static getAvailableIDs() method.

 

To get all available IDs:

  • Java
  • timezone
  • Add new comment
  • Read more

Format and cast a date to a timezone

Problem:

You want to format a date and cast it to a timezone.

Solution:

The Java DateFormat class can cast a date to a new time zone at the same time as formatting it.  This can be accomplished simply by specifying a TimeZone on the DateFormat object.

 

To format and cast a date to PST:

  • date formatting
  • timezone
  • Add new comment
  • Read more

If you are testing any of these recipes in Eclipse and the characters are not displaying correctly in your console visit http://i18ncookbook.com/eclipse_settings.

This site is ad supported.  I hope you find something among our sponsors worth clicking. ;)

i18n search

Google
Custom Search
Syndicate content

Search

Tags in Tags

calendar date icu4j Java Locale number format numberformat parse spellout timezone transliteration transliterator
more tags

User login

  • Create new account
  • Request new password
  • java cookbook
  • about the author