The i18n Cookbook - recipies for a global society

  • java cookbook
  • about the author
Home › Java Internationalization Cookbook › Dates and Times › Formating dates and times

Java Cookbook

  • Java Internationalization Cookbook
    • Locales
    • Dates and Times
      • Calendars
      • Formating dates and times
        • Format a time amount
        • Format a time interval
        • Format and cast a date to a timezone
        • Get all time zone ids
        • Get an array of day names
        • Get an array of timezone ids for offset
        • Get the best date format pattern
        • Get the display name for a Timezone
        • Parse a formatted date string
    • Numerical Systems
    • Misc
    • Resource Bundles
    • Unicode, Transliteration, and Charactersets

Get an array of day names

 Problem:

You want to retrieve all of the day of the week names for a locale.

Solution:

The DateFormatSymbols class contains a wealth of information useful to the localization programmer.  You can easily retrieve day names, month names, era names, etc...

 

To get the days of the week in Korean and English:

//Get a DateFormatSymbols object using a locale as an argument

DateFormatSymbols dfsKorean = new DateFormatSymbols(Locale.KOREAN);

DateFormatSymbols dfsEnglish = new DateFormatSymbols(Locale.ENGLISH);

//Get an array of weekday names

String[] kWeekdays = dfsKorean.getWeekdays();

String[] eWeekdays = dfsEnglish.getWeekdays();

//Loop through the array and output the names

for(int x = 1; x < 8; x++){

    System.out.println(eWeekdays[x] + " = " + kWeekdays[x]);

}

 

 


The output:

Sunday = 일요일

Monday = 월요일

Tuesday = 화요일

Wednesday = 수요일

Thursday = 목요일

Friday = 금요일

Saturday = 토요일

 

‹ Get all time zone ids up Get an array of timezone ids for offset ›
  • date
  • DateFormatSymbols
  • day names
  • 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