Java Representing Dates in Other Epochs
You need to deal with dates in a form other than the Gregorian Calendar used in the
Western world.
Solution
Download the IBM calendar classes.
Explained
The only nonabstract Calendar subclass is the GregorianCalendar , as mentioned pre-
viously. 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.
The calendar classes in ICU4J work in a similar fashion to the standard
GregorianCalendar class, but they have constants for month names and other infor-
mation 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 import import import java.util.Locale; com.ibm.icu.util.Calendar; java.text.DateFormat; com.ibm.icu.util.IslamicCalendar; public class IBMCalDemo { public static void main(String[] args) { Locale ar_loc = new Locale("ar"); Calendar c = new com.ibm.icu.util.IslamicCalendar( ); 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.
No comments:
Post a Comment