private String weekArrays[] = {"周日","周一","周二","周三","周四","周五","周六"};
/**
* @param date format is 2012-9-18
* @return weekday
*/
private String getWeekday(final String date) {
if(TextUtils.isEmpty(date)) {
return null;
}
int year = 0;
int month = 0;
int day = 0;
try {
String[] array = date.split("-");
int[] arrayInt = new int[array.length];
for (int i = 0; i < array.length; i++) {
arrayInt[i] = Integer.parseInt(array[i]);
if(i == 0) {
year = arrayInt[0];
} else if(i == 1){
month = arrayInt[1];
} else if(i == 2){
day = arrayInt[2];
}
}
} catch (Exception e) {
e.printStackTrace();
}
Calendar cal = Calendar.getInstance();
if(year > 0 && month >= 0 && day >= 0) {
cal.set(year, month, day);
}
int weekday = cal.get(Calendar.DAY_OF_WEEK);
String week = null;
if (weekday > 0 && weekday < 8) {
week = weekArrays[weekday - 1];
}
return week;
}
PS:传入日期格式一定要为2012-9-18