1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String Date = "2020-08-03"; //定义初始是周一
Date testdate = sdf.parse(Date);
Calendar cal = Calendar.getInstance();
cal.setTime(testdate);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.MONDAY){
System.out.println(sdf.format(cal.getTime())+"========="+"是周一=========");
}
//日期加一天
cal.add(Calendar.DATE,1);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.TUESDAY) {
System.out.println(sdf.format(cal.getTime())+"========="+"是周二=========");
}
cal.add(Calendar.DATE,1);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.WEDNESDAY){
System.out.println(sdf.format(cal.getTime())+"========="+"是周三=========");
}
cal.add(Calendar.DATE,1);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.THURSDAY){
System.out.println(sdf.format(cal.getTime())+"========="+"是周四=========");
}
cal.add(Calendar.DATE,1);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.FRIDAY){
System.out.println(sdf.format(cal.getTime())+"========="+"是周五=========");
}
cal.add(Calendar.DATE,1);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY){
System.out.println(sdf.format(cal.getTime())+"========="+"是周六=========");
}
cal.add(Calendar.DATE,1);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(sdf.format(cal.getTime())+"========="+"是周日=========");
}
Edited on Views times