3

例如,今天我希望字符串为“Sunday”。我知道如何在 Java 6 中做到这一点:

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

但这不能在 Java 5 中编译。知道怎么做吗?

4

2 回答 2

4

您可以使用日期格式:

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 回答