Recipe 6.3 Representing Dates in Other Epochs


You need to deal with dates in a form other than the Gregorian Calendar used in the Western world.


Download the IBM calendar classes.


The only nonabstract Calendar subclass is the GregorianCalendar, as mentioned previously. However, other calendar classes do exist. IBM has a set of calendars Hebrew, Islamic, Buddhist, Japanese, and even an Astronomical Calendar class that covers most of the rest of the world. This work has been open sourced and is now part of a project called International Components for Unicode for Java, which can be found at

The calendar classes in ICU4J work in a similar fashion to the standard GregorianCalendar class, but they have constants for month names and other information relevant to each particular calendar. They are not subclassed from java.util.Calendar, however, so they must be referred to by their full class name:

import java.util.Locale; import; import java.text.DateFormat; import; public class IBMCalDemo {         public static void main(String[] args) {                 Locale ar_loc = new Locale("ar");                 Calendar c = new );                 DateFormat d = DateFormat.getDateInstance(DateFormat.LONG, ar_loc);                 System.out.println(d.format(c.getTime( )));         } }

I can't include the textual output because of font limitations. The icu4j package includes a multicalendar demo application whose output is shown in Figure 6-1.

Figure 6-1. IBMCalDemo in action

Java Cookbook
Java Cookbook, Second Edition
ISBN: 0596007019
EAN: 2147483647
Year: 2003
Pages: 409
Authors: Ian F Darwin

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: