Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,今天我希望字符串为“Sunday”。我知道如何在 Java 6 中做到这一点:
String day = Calendar.getInstance().getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());
但这不能在 Java 5 中编译。知道怎么做吗?
您可以使用日期格式:
SimpleDateFormat weekdayFormat = new SimpleDateFormat("EEEE"); System.out.println(weekdayFormat.format(new Date()));
我还没有尝试过,但这应该可以。
switch (Calendar.getInstance ().get (Calendar.DAY_OF_WEEK)) { ... }