代码—五天前是星期几

 1 package testweb;
 2 
 3 import java.util.*;
 4 import java.text.*;
 5 
 6 public class Test {
 7 
 8     public static void main(String[] args) {
 9 
10         /*
11          * SimpleDateFormat sdf = new SimpleDateFormat("E"); Calendar cal =
12          * Calendar.getInstance(); cal.add(Calendar.DATE,-5); Date date =
13          * cal.getTime(); String time_str = sdf.format(date); if
14          * (time_str.equals("星期天")){ System.out.println(time_str+",放假"); }else{
15          * System.out.println(time_str+",上学"); }
16          */
17 
18         // 获取当天的时间
19         Calendar cal = Calendar.getInstance();
20         // 把日历,按天,往前翻5天
21         cal.add(Calendar.DATE, -5);
22 
23         int day_of_week = cal.get(Calendar.DAY_OF_WEEK);
24         // 1,7分别就是周末(星期6,星期天)
25 
26         if (day_of_week == 1 || day_of_week == 7) {
27             System.out.println(day_of_week + ",放假");
28         } else {
29             System.out.println(day_of_week + ",上学");
30         }
31     }
32 
33 }
原文地址:https://www.cnblogs.com/renjingni980207/p/6858016.html