/**
* 根据日期获取星期
* @param args
*/
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
String week = dateToWeek(date);
System.out.println(week);
}
/**
* 根据日期获取 星期
* @param date
* @return
*/
public static String dateToWeek(Date date) {
String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
Calendar cal = Calendar.getInstance();
try {
cal.setTime(date);
} catch (Exception e) {
e.printStackTrace();
}
//一周的第几天
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;
return weekDays[w];
}