/**
* start
* 本周开始时间戳 - 以星期一为本周的第一天
*/
public long getWeekStartTime() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyyyMMdd", Locale. getDefault());
Calendar cal = Calendar.getInstance();
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0,
0, 0);
int day_of_week = cal.get(Calendar. DAY_OF_WEEK) - 1;
if (day_of_week == 0 ) {
day_of_week = 7 ;
}
cal.add(Calendar.DATE , -day_of_week + 1 );
return cal.getTime().getTime();
}
/**
* end
* 本周结束时间戳 - 以星期一为本周的第一天
*/
public long getWeekEndTime() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyyyMMdd", Locale. getDefault());
Calendar cal = Calendar.getInstance();
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 23,
59, 59);
int day_of_week = cal.get(Calendar. DAY_OF_WEEK) - 1;
if (day_of_week == 0 ) {
day_of_week = 7 ;
}
cal.add(Calendar.DATE , -day_of_week + 7 );
return cal.getTime().getTime() ;
}
之前踩了个坑,周日生成出来是下周一和周日的时间戳,找了好久找到这篇
https://blog.csdn.net/zhuwentao2150/article/details/52084642
稍微修改了一点我需要的格式 记录一下