Commit 495c56c6 authored by yanzg's avatar yanzg

Merge branch 'ver1.1' of http://192.168.0.204/yzg/yzg-util

parents 2e66e257 f7e415f5
......@@ -371,7 +371,14 @@ public class DateHelper {
*/
public static Date getWeekStart(Date date) {
Calendar cal = getDayCalendarBegin(date);
cal.setWeekDate(cal.getWeekYear(), cal.get(Calendar.WEEK_OF_YEAR), 2);
// 周日
int weekOfYear;
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
weekOfYear = cal.get(Calendar.WEEK_OF_YEAR) - 1;
} else {
weekOfYear = cal.get(Calendar.WEEK_OF_YEAR);
}
cal.setWeekDate(cal.getWeekYear(), weekOfYear, 2);
setDayStart(cal);
return cal.getTime();
}
......@@ -384,7 +391,14 @@ public class DateHelper {
*/
public static Date getWeekEnd(Date date) {
Calendar cal = getDayCalendarBegin(date);
cal.setWeekDate(cal.getWeekYear(), cal.get(Calendar.WEEK_OF_YEAR) + 1, 1);
// 周日
int weekOfYear;
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
weekOfYear = cal.get(Calendar.WEEK_OF_YEAR);
} else {
weekOfYear = cal.get(Calendar.WEEK_OF_YEAR) + 1;
}
cal.setWeekDate(cal.getWeekYear(), weekOfYear, 1);
setDayEnd(cal);
return cal.getTime();
}
......
......@@ -21,6 +21,12 @@ public class TestDateHelper {
System.out.println("本周:" + DateHelper.getDateTimeString(DateHelper.getWeekStart(date)));
System.out.println("本周:" + DateHelper.getDateTimeString(DateHelper.getWeekEnd(date)));
System.out.println("2022-11-27 周:" + DateHelper.getDateTimeString(DateHelper.getWeekStart(DateHelper.getDateTime("2022-11-27"))));
System.out.println("2022-11-27 周:" + DateHelper.getDateTimeString(DateHelper.getWeekEnd(DateHelper.getDateTime("2022-11-27"))));
System.out.println("2022-11-26 周:" + DateHelper.getDateTimeString(DateHelper.getWeekStart(DateHelper.getDateTime("2022-11-26"))));
System.out.println("2022-11-26 周:" + DateHelper.getDateTimeString(DateHelper.getWeekEnd(DateHelper.getDateTime("2022-11-26"))));
System.out.println("本季度:" + DateHelper.getDateTimeString(DateHelper.getMonth3Start(date)));
System.out.println("本季度:" + DateHelper.getDateTimeString(DateHelper.getMonth3End(date)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment