/**
* 根据时间日期获取当天是周几
* @param datetime 日期
* @return 周几
*/
public static String dateToWeek(String dateTime) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
Calendar cal = Calendar.getInstance();
Date date;
try {
date = sdf.parse(dateTime);
cal.setTime(date);
} catch (Exception e) {
e.printStackTrace();
}
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
return weekDays[w];
}
如果对你有帮助请给小弟打赏下,祝你成功。