- 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
- Calendars
- Numerical Systems
- Misc
- Resource Bundles
- Unicode, Transliteration, and Charactersets
Java Cookbook
Get an array of Holidays
Problem:
You want to know what holidays are common for a locale.
Solution:
Icu4j contains a system to help the Java developer handle international holidays. The Holiday class is simple to use, and has failry complete data.
To get an Array of all Holidays for Mexico:
//Get a ULocale
ULocale locale = new ULocale("es_MX");
//Get an array of Holidays
Holiday[] holidays = Holiday.getHolidays(locale);
//Loop through all of the Holidays and output the localized display name
for(int x = 0; x < holidays.length; x++){
System.out.println(holidays[x].getDisplayName(locale));
}
The output:
New Year's Day
Constitution Day
Benito Juárez Day
May Day
Cinco de Mayo
Navy Day
Independence Day
Día de la Raza
All Saints' Day
Day of the Dead
Revolution Day
Flag Day
Christmas
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
Custom Search