/**
* 判断当前日期是星期几<br>
* <br>
* @param pTime 修要判断的时间<br>
* @return dayForWeek 判断结果<br>
* @Exception 发生异常<br>
*/
public static int dayForWeek(String pTime) throws Exception {
//注意参数的样式为yyyy-MM-dd,必须让参数样式与所需样式统一
format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(format.parse(pTime));
int dayForWeek = 0;
if(c.get(Calendar.DAY_OF_WEEK) == 1){
dayForWeek = 7;
}else{
dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
}
return dayForWeek;
}
Java——根据日期返回周几
最新推荐文章于 2024-03-25 08:57:12 发布