Java顯示星期一至五
如何顯示在星期一至五的名稱嗎?
解決方法
本示例以短格式顯示星期一到星期五,使用DateFormatSymbols類的DateFormatSymbols().getWeekdays() 方法。
import java.text.SimpleDateFormat; import java.text.DateFormatSymbols; public class Main { public static void main(String[] args) { String[] weekdays = new DateFormatSymbols().getWeekdays(); for (int i = 2; i < (weekdays.length-1); i++) { String weekday = weekdays[i]; System.out.println("weekday = " + weekday); } } }
結果
上麵的代碼示例將產生以下結果。
weekday = Monday weekday = Tuesday weekday = Wednesday weekday = Thursday weekday = Friday