我需要获得周跨度:周开始(Mo)| 一年中的星期几结束(星期日)。
例如,对于 5.9.2019,它应该是 241-247(从 0 开始的天数)。
但是,我的方法产生 250 | 249
public static Pair<Integer, Integer> getWeekSpan(Timestamp date) {
Pair<Integer, Integer> result = new Pair<Integer, Integer>();
Calendar cal = timestampToCalendar(date);
// start of week
cal.set(Calendar.DAY_OF_WEEK, cal.getActualMinimum(Calendar.DAY_OF_WEEK));
result.setKey(cal.get(Calendar.DAY_OF_YEAR) - 1);
// end of week
cal.set(Calendar.DAY_OF_WEEK, cal.getActualMaximum(Calendar.DAY_OF_WEEK));
result.setValue(cal.get(Calendar.DAY_OF_YEAR) - 1);
return result;
}
public static Calendar timestampToCalendar(Timestamp timestamp) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timestamp.getTime());
return cal;
}