/**
* 根据weekNo(本周为0,上周为-1,下周为1),week(Calendar.XXX)获取日期
* @author guandesong
* @date 2015-11-4 下午4:57:53
* @param week
* @return
*/
public static String getLastWeekDate(int weekNo,int week){
Calendar date=Calendar.getInstance(Locale.CHINA);
date.setFirstDayOfWeek(Calendar.MONDAY);//将每周第一天设为星期一,默认是星期天
date.add(Calendar.WEEK_OF_MONTH,weekNo);//weekNo本周为0,上周为-1,下周为1,以此类推
date.set(Calendar.DAY_OF_WEEK, week);//比如把日子设为星期天week值为Calendar.SUNDAY
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd");
String weekString = sdf.format(date.getTime());
System.out.println(weekString);
return weekString;
}
/**
* 根据weekNo和week判断今天是否是该日期
* @author guandesong
* @date 2015-11-5 上午11:57:08
* @param weekNo
* @param week
* @return
*/
public static boolean todayIsSelectedDate(int weekNo,int week){
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd");
String weekString = sdf.format(new Date().getTime());
if(weekString.equals(getLastWeekDate(weekNo,week))){
return true;
}else
return false;
}
根据weekNo(本周为0,上周为-1,下周为1),week(Calendar.XXX)获取日期,以及根据weekNo和week判断今天是否是该日期
最新推荐文章于 2023-07-12 18:16:17 发布