import org.joda.time.LocalDateTime;
/**
* 获取本周开始时间和结束时间(周一-周日)
* @return 起止时间
*/
public static Date[] getWeekRangeDate() {
//当前时间
LocalDateTime now = LocalDateTime.now();
//开始时间
Date startTimeInWeek = now.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).withDayOfWeek(DateTimeConstants.MONDAY).toDate();
//结束时间
Date endTimeInWeek = now.withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59).withDayOfWeek(DateTimeConstants.SUNDAY).toDate();
return new Date[]{startTimeInWeek,endTimeInWeek};
}
验证
public static void main(String[] args) {
Date[] weekRangeDate = DateUtils.getWeekRangeDate();
SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str1=f.format(weekRangeDate[0]);
String str2=f.format(weekRangeDate[1]);
System.out.println(str1 +" "+ str2);
}