//三、用程式判斷2018年2月14日是星期幾。
阿新 • • 發佈:2019-01-23
public class Demo03 { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR,2018); //month從0開始至11,代表1-12 calendar.set(Calendar.MONTH,1); calendar.set(Calendar.DAY_OF_MONTH,14); int month = calendar.get(Calendar.MONTH)+1; String weekday = getWeek(calendar.get(Calendar.DAY_OF_WEEK)); System.out.println(weekday); } public static String getWeek(int a){ //西方的星期的開始為週日,中國為週一。 String[] strings = {" ","星期日","星期一","星期二","星期三","星期四","星期五","星期六"}; return strings[a]; } }