Locales for Calendar : Calendar « I18N « Java






Locales for Calendar

Locales for Calendar
 
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Locale;

public class DaysOfTheWeek {

  public static void main(String argv[]) {

    Locale usersLocale;

    if (argv.length == 2)
      usersLocale = new Locale(argv[0], argv[1]);
    else if (argv.length == 3)
      usersLocale = new Locale(argv[0], argv[1], argv[2]);
    else
      usersLocale = Locale.getDefault();

    DateFormatSymbols dfs = new DateFormatSymbols(usersLocale);
    String weekdays[] = dfs.getWeekdays();

    Calendar cal = Calendar.getInstance(usersLocale);

    int firstDayOfWeek = cal.getFirstDayOfWeek();
    int dayOfWeek;

    for (dayOfWeek = firstDayOfWeek; dayOfWeek < weekdays.length; dayOfWeek++)
      System.out.println(weekdays[dayOfWeek]);

    for (dayOfWeek = 0; dayOfWeek < firstDayOfWeek; dayOfWeek++)
      System.out.println(weekdays[dayOfWeek]);
  }
}

           
         
  








Related examples in the same category

1.Calendar Manipulation for I18N (Internationalization)Calendar Manipulation for I18N (Internationalization)
2.Create an instance using Japan's time zone and set it with the local UTC
3.Get the foreign time
4.Given a time of 10am in Japan, get the local time