Java如何获取工作日名称列表?
下面的示例代码可帮助您获取所有工作日名称作为字符串数组。第一种方法getWeekdays()返回全名字符串,第二种方法getShortWeekdays()返回工作日的简称。
package org.nhooo.example.text; import java.text.DateFormatSymbols; public class WeekdayNames { public static void main(String[] args) { DateFormatSymbols dfs = new DateFormatSymbols(); String[] weekdays = dfs.getWeekdays(); for (String weekday : weekdays) { System.out.println("weekday = " + weekday); } String[] shortWeekdays = dfs.getShortWeekdays(); for (String shortWeekday : shortWeekdays) { System.out.println("shortWeekday = " + shortWeekday); } } }
上面代码的结果是:
weekday = weekday = Sunday weekday = Monday weekday = Tuesday weekday = Wednesday weekday = Thursday weekday = Friday weekday = Saturday shortWeekday = shortWeekday = Sun shortWeekday = Mon shortWeekday = Tue shortWeekday = Wed shortWeekday = Thu shortWeekday = Fri shortWeekday = Sat