/**
* 根据日期获取当前是星期几
*/
public static void main(String[] args) throws ParseException {
String dates = "2020-12-1";
Calendar cal = Calendar.getInstance();
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
Date d =f.parse(dates);
cal.setTime(d);
//因为数组下标从0开始,而返回的是数组的内容,是数组{1,2,3,4,5,6,7}中用1~7来表示,所以要减1
int w=cal.get(Calendar.DAY_OF_WEEK)-1;
if(w==0) {
w=7;
};
System.out.println("星期"+w);
//输出:星期2
}