The i18n Cookbook - recipies for a global society

  • java cookbook
  • about the author
Home

Java Cookbook

  • Java Internationalization Cookbook

date formatting

Format a time amount

Problem:

You want to format a time amount like "5 days" for a locale.

Solution:

TimeUnitFormat from icu4j provides some excellent formatting options for time units.  To use you specify a TimeUnitAmount which contains an amount and a unit.  Then specify a locale on the TimeUnitFormat.

To format 1 day in French:

  • date formatting
  • format
  • 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

Formating dates and times

Problem:

You want to format a date correctly for a locale.

Solution:

Formatting dates and times correctly for a locale can prove challenging, especially considering the variety of possibilities.  Thankfully, Java provides a number of date formatting methods and classes.  icu4j adds even more tools to the programmers toolbox.

 

To format a date you need to get an instance of the DateFormat class passing the locale in:

  • DateFormat
  • date formatting
  • formatting
  • Java
  • 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