/**一周周期相关*/
public class MyWeekDate {
/**开始时间*/
public long mLong_begin;
/**开始日期*/
public String mStr_begin;
/**结束时间*/
public long mLong_end;
/**结束日期*/
public String mStr_end;
}
/**
* 获取time所在日期一周的时间段(周一00:00:00---周日 23:59:59)* @param time
* @return
*/
public static MyWeekDate getWeekDate(long time){
MyWeekDate weekDate = new MyWeekDate();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(time);
SimpleDateFormat df = new SimpleDateFormat("MM月dd日");
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // 获取本周一的日期
//设置0点0分0秒
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
weekDate.mLong_begin = cal.getTimeInMillis();
weekDate.mStr_begin = df.format(cal.getTime());
//实际上Calendar.SUNDAY为本周第一天,在周一之前
//按照我们的习惯,周一为一周第一天,所以最后为下一周的星期天
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
cal.add(Calendar.WEEK_OF_YEAR, 1);
//设置23:59:59
//Calendar.HOUR_OF_DAY--24小时制;Calendar.HOUR--12小时制
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.MILLISECOND, 999);
weekDate.mLong_end = cal.getTimeInMillis();
weekDate.mStr_end = df.format(cal.getTime());
return weekDate;
}
/**
* 判断时间是否超出本周
* @param time
* @param myWeekDate
* @return
*/
public static boolean isOutOfWeek(long time,MyWeekDate myWeekDate){
if (time > myWeekDate.mLong_end || time < myWeekDate.mLong_begin)
return false;
return true;
}