0

I have this code:

public static String WEEK_DAY_SHORT = "c";

public static String getWeekDay(int day) {
    GregorianCalendar calendar = new GregorianCalendar();

    calendar.set(Calendar.DAY_OF_WEEK, day + 2);

    DateFormat formatter = new SimpleDateFormat(WEEK_DAY_SHORT + ", " + DATE);
    return formatter.format(calendar.getTime());
}

when I run this method on 4.1.2 everything is okay and I get outputs like Mo;Di;Mi;... But when I run this on 2.2 I get the following error:

java.lang.IllegalArgumentException: Unknown pattern character - 'c'
        at java.text.SimpleDateFormat.validateFormat(SimpleDateFormat.java:379)
        at java.text.SimpleDateFormat.validatePattern(SimpleDateFormat.java:428)
        at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:499)
        at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:363)
        at
de.MayerhoferSimon.Vertretungsplan.Utils.DateHelper.getWeekDay(DateHelper.java:54)

the same is when I try "cc" for a short dayname or "cccc" for a long dayname.

Are there differences in the SimpleDateFormat class between 2.2 and 4.1.2 ? And how can I fix this?

4

1 回答 1

2

尝试使用“EEEE”作为日名,使用“EEE”作为短日名

于 2013-07-23T18:25:04.207 回答