자바 획득 오늘 (어느 날) 은 무슨 요일 / 무슨 요일
736 단어 자바
/**
*@param date 、 “2013-06-03”
*@return 1 、2 、3 、4 、5 、6 、7
*/
public static int getDayofweek(String date){
Calendar cal = Calendar.getInstance();
// cal.setTime(new Date(System.currentTimeMillis()));
if (date.equals("")) {
cal.setTime(new Date(System.currentTimeMillis()));
}else {
cal.setTime(new Date(getDateByStr2(date).getTime()));
}
return cal.get(Calendar.DAY_OF_WEEK);
}
public static Date getDateByStr2(String dd)
{
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
Date date;
try {
date = sd.parse(dd);
} catch (ParseException e) {
date = null;
e.printStackTrace();
}
return date;
}