Java DateFormatSymbols change symbols

Description

Java DateFormatSymbols change symbols

import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
  public static void main(String[] args) throws Exception {
    DateFormatSymbols  symbols = new DateFormatSymbols(new Locale("en", "US"));
    String[] defaultDays = symbols.getShortWeekdays();

    for (int i = 0; i < defaultDays.length; i++) {
      System.out.print(defaultDays[i] + "  ");
    }/*from  w  ww  .j a v  a  2s.co m*/

    String[] capitalDays = { "", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
    symbols.setShortWeekdays(capitalDays);

    String[] modifiedDays = symbols.getShortWeekdays();
    for (int i = 0; i < modifiedDays.length; i++) {
      System.out.print(modifiedDays[i] + "  ");
    }

    SimpleDateFormat formatter = new SimpleDateFormat("E", symbols);
    Date  today = new Date();
    String result = formatter.format(today);
    System.out.println("Today's day of the week: " + result);
  }
}



PreviousNext

Related