public static String dateToWeek(String datetime) {
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
Calendar cal = Calendar.getInstance();
Date datet = null;
try {
datet = f.parse(datetime);
cal.setTime(datet);
} catch (ParseException | java.text.ParseException e) {
e.printStackTrace();
}
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;
return weekDays[w];
}
SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
Date date = ft.parse("2021-05-20");
SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
String week = sdf.format(date);