The i18n Cookbook - recipies for a global society

  • java cookbook
  • about the author
Home › Java Internationalization Cookbook › Dates and Times › Calendars

Java Cookbook

  • Java Internationalization Cookbook
    • Locales
    • Dates and Times
      • Calendars
        • Gregorian Calendar
        • Hebrew Calendar
        • Japanese Calendar
        • Chinese Calendar
        • Find the Chinese zodiac for a Gregorian year
        • Get the name of the current month
        • Get the first day of the week
        • Add time to Calendar
        • Get an array of Holidays
        • Find the date for the Chinese New Year
        • Get all the Era names for the Japanese Calendar
        • Get the Japanese era for a Gregorian date
      • Formating dates and times
    • Numerical Systems
    • Misc
    • Resource Bundles
    • Unicode, Transliteration, and Charactersets

Japanese Calendar

 Problem:

You want a calendar that is most familiar to your Japanese users.

Solution:

The Japanese calendar is identical to the Gregorian calendar, except the year is represented by the year of the emperor's reign.  It is currently the 20th year of the Heisei emperor's reign, so the year is Heisei 20.

You can create a Japanese calendar by using icu4j .

To create a calendar object:

ULocale ul = new ULocale("ja_JP@calendar=japanese");

 

To format a simple date example:

ULocale ul = new ULocale("en@calendar=japanese");

DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, ul);

System.out.println(df.format(new Date()));

 

 The result is "Friday, November 28, 20 Heisei".  If we change the ULocale to japanese the output is "平成20年11月28日金曜日"

To get the era of the current date:

//Get Japanese locale with attribute specifying japanese calendar

ULocale ul = new ULocale("ja_JP@calendar=japanese"); 

//calling getInstance using the locale bearing a calendar type will give us the appropriate locale

Calendar cal = Calendar.getInstance(ul);

//Output the era number.  This is a largely arbitrary number, but it can be used to compare

//against the static constants on Japanese Calendar

System.out.println(cal.get(JapaneseCalendar.ERA) + " Heisei era = " + JapaneseCalendar.HEISEI);

 

‹ Hebrew Calendar up Chinese Calendar ›
  • calendar
  • icu4j
  • japanese calendar
  • Java
  • Printer-friendly version
  • Add new comment

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

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