3

For example for today I want string as "Sunday". I know how to do this in Java 6:

String day = Calendar.getInstance().getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());

But this doesn't compile in Java 5. Any idea how to do this?

4

2 に答える 2

4

DateFormat を使用できます。

SimpleDateFormat weekdayFormat = new SimpleDateFormat("EEEE");
System.out.println(weekdayFormat.format(new Date()));

私はそれを試していませんが、これはうまくいくはずです。

于 2011-10-30T17:15:17.417 に答える
1
switch (Calendar.getInstance ().get (Calendar.DAY_OF_WEEK)) { ... }
于 2011-10-30T17:20:59.510 に答える