/**
* @Description 确定日期为周几
* @param date 2021-02-02
* @Throws
* @Return int
* @Date 2021-02-02 16:29:52
* @Author WangKun
**/
public static int getDayWeek(String date){
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd" );
Calendar c = Calendar.getInstance();
c.setTime(format.parse(date));
int dayForWeek = 0 ;
if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){
dayForWeek = 7 ;
}else {
dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1 ;
}
return dayForWeek;
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
}
/**
* @Description 转换名称
* @param week
* @Throws
* @Return java.lang.String
* @Date 2021-02-02 16:30:16
* @Author WangKun
**/
public static String getWeekConvert(int week) {
String name = null;
switch (week) {
case 1:
name = "周一";
break;
case 2:
name = "周二";
break;
case 3:
name = "周三";
break;
case 4:
name = "周四";
break;
case 5:
name = "周五";
break;
case 6:
name = "周六";
break;
case 7:
name = "周日";
break;
default:
}
return name;
}