/**
*@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;
}
java 获取今天(某一天)是星期几/周几
最新推荐文章于 2024-06-18 14:57:23 发布