|
@@ -1,5 +1,6 @@
|
|
package com.platform.common.util;
|
|
package com.platform.common.util;
|
|
|
|
|
|
|
|
+import com.platform.common.exception.BusinessException;
|
|
import lombok.experimental.UtilityClass;
|
|
import lombok.experimental.UtilityClass;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
@@ -28,7 +29,7 @@ public class DateUtils {
|
|
public final static String PATTERN_YMD_ZH_NO = "yyyy年M月d日";
|
|
public final static String PATTERN_YMD_ZH_NO = "yyyy年M月d日";
|
|
public final static String PATTERNYMDHMS = "yyyyMMddHHmmss";
|
|
public final static String PATTERNYMDHMS = "yyyyMMddHHmmss";
|
|
|
|
|
|
- public final static String PATTERNYMD= "yyyyMMdd";
|
|
|
|
|
|
+ public final static String PATTERNYMD = "yyyyMMdd";
|
|
|
|
|
|
private final static ZoneId ZONE_ID = ZoneId.systemDefault();
|
|
private final static ZoneId ZONE_ID = ZoneId.systemDefault();
|
|
|
|
|
|
@@ -83,7 +84,7 @@ public class DateUtils {
|
|
*/
|
|
*/
|
|
public static LocalDateTime getFirstDayOfThisMonth() {
|
|
public static LocalDateTime getFirstDayOfThisMonth() {
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
- LocalDateTime firstday = now.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
|
|
|
|
|
|
+ LocalDateTime firstday = now.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
|
|
return firstday;
|
|
return firstday;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -94,8 +95,8 @@ public class DateUtils {
|
|
*/
|
|
*/
|
|
public static LocalDateTime getLastDayOfThisMonth() {
|
|
public static LocalDateTime getLastDayOfThisMonth() {
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
- LocalDateTime lastDay = now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
|
|
|
|
- return lastDay ;
|
|
|
|
|
|
+ LocalDateTime lastDay = now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
|
|
|
|
+ return lastDay;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -105,7 +106,7 @@ public class DateUtils {
|
|
*/
|
|
*/
|
|
public static LocalDateTime getFirstDayOfThisYear(int year) {
|
|
public static LocalDateTime getFirstDayOfThisYear(int year) {
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
- LocalDateTime firstday = now.withYear(year).with(TemporalAdjusters.firstDayOfYear()).withHour(0).withMinute(0).withSecond(0);
|
|
|
|
|
|
+ LocalDateTime firstday = now.withYear(year).with(TemporalAdjusters.firstDayOfYear()).withHour(0).withMinute(0).withSecond(0);
|
|
return firstday;
|
|
return firstday;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -116,8 +117,8 @@ public class DateUtils {
|
|
*/
|
|
*/
|
|
public static LocalDateTime getLastDayOfThisYear(int year) {
|
|
public static LocalDateTime getLastDayOfThisYear(int year) {
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
- LocalDateTime lastDay = now.withYear(year).with(TemporalAdjusters.lastDayOfYear()).withHour(23).withMinute(59).withSecond(59);
|
|
|
|
- return lastDay ;
|
|
|
|
|
|
+ LocalDateTime lastDay = now.withYear(year).with(TemporalAdjusters.lastDayOfYear()).withHour(23).withMinute(59).withSecond(59);
|
|
|
|
+ return lastDay;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -127,7 +128,7 @@ public class DateUtils {
|
|
*/
|
|
*/
|
|
public static LocalDateTime getFirstDayOfMonth(Integer month) {
|
|
public static LocalDateTime getFirstDayOfMonth(Integer month) {
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
- LocalDateTime firstday = now.withMonth(month).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
|
|
|
|
|
|
+ LocalDateTime firstday = now.withMonth(month).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
|
|
return firstday;
|
|
return firstday;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -138,7 +139,7 @@ public class DateUtils {
|
|
*/
|
|
*/
|
|
public static LocalDateTime getFirstDayOfMonth(Integer year, Integer month) {
|
|
public static LocalDateTime getFirstDayOfMonth(Integer year, Integer month) {
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
- LocalDateTime firstday = now.withYear(year).withMonth(month).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
|
|
|
|
|
|
+ LocalDateTime firstday = now.withYear(year).withMonth(month).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
|
|
return firstday;
|
|
return firstday;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -149,8 +150,8 @@ public class DateUtils {
|
|
*/
|
|
*/
|
|
public static LocalDateTime getLastDayOfMonth(Integer month) {
|
|
public static LocalDateTime getLastDayOfMonth(Integer month) {
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
- LocalDateTime lastDay = now.withMonth(month).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
|
|
|
|
- return lastDay ;
|
|
|
|
|
|
+ LocalDateTime lastDay = now.withMonth(month).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
|
|
|
|
+ return lastDay;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -160,17 +161,18 @@ public class DateUtils {
|
|
*/
|
|
*/
|
|
public static LocalDateTime getLastDayOfMonth(Integer year, Integer month) {
|
|
public static LocalDateTime getLastDayOfMonth(Integer year, Integer month) {
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
- LocalDateTime lastDay = now.withYear(year).withMonth(month).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
|
|
|
|
- return lastDay ;
|
|
|
|
|
|
+ LocalDateTime lastDay = now.withYear(year).withMonth(month).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
|
|
|
|
+ return lastDay;
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 指定年月的最后一天开始时间
|
|
* 指定年月的最后一天开始时间
|
|
*
|
|
*
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static LocalDateTime getFirstDayOfMonth(LocalDate month) {
|
|
public static LocalDateTime getFirstDayOfMonth(LocalDate month) {
|
|
- LocalDateTime day = month.atStartOfDay();
|
|
|
|
- LocalDateTime firstday = day.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
|
|
|
|
|
|
+ LocalDateTime day = month.atStartOfDay();
|
|
|
|
+ LocalDateTime firstday = day.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
|
|
return firstday;
|
|
return firstday;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -180,8 +182,8 @@ public class DateUtils {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static LocalDateTime getLastDayOfMonth(LocalDate month) {
|
|
public static LocalDateTime getLastDayOfMonth(LocalDate month) {
|
|
- LocalDateTime day = month.atStartOfDay();
|
|
|
|
- LocalDateTime lastDay = day.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
|
|
|
|
|
|
+ LocalDateTime day = month.atStartOfDay();
|
|
|
|
+ LocalDateTime lastDay = day.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
|
|
return lastDay;
|
|
return lastDay;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -193,7 +195,7 @@ public class DateUtils {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static LocalDateTime getFirstDayOfWeek(int year, int week) {
|
|
public static LocalDateTime getFirstDayOfWeek(int year, int week) {
|
|
- WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY,1);
|
|
|
|
|
|
+ WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1);
|
|
LocalDateTime ldt = LocalDateTime.now()
|
|
LocalDateTime ldt = LocalDateTime.now()
|
|
.withYear(year)
|
|
.withYear(year)
|
|
.with(weekFields.weekOfYear(), week)
|
|
.with(weekFields.weekOfYear(), week)
|
|
@@ -209,7 +211,7 @@ public class DateUtils {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static LocalDateTime getLastDayOfWeek(int year, int week) {
|
|
public static LocalDateTime getLastDayOfWeek(int year, int week) {
|
|
- WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY,1);
|
|
|
|
|
|
+ WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1);
|
|
LocalDateTime ldt = LocalDateTime.now()
|
|
LocalDateTime ldt = LocalDateTime.now()
|
|
.withYear(year)
|
|
.withYear(year)
|
|
.with(weekFields.weekOfYear(), week)
|
|
.with(weekFields.weekOfYear(), week)
|
|
@@ -224,7 +226,7 @@ public class DateUtils {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static LocalDateTime getLastDayOfWeekOfYear(int year) {
|
|
public static LocalDateTime getLastDayOfWeekOfYear(int year) {
|
|
- WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY,1);
|
|
|
|
|
|
+ WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1);
|
|
LocalDateTime lastDayOfYear = DateUtils.getLastDayOfThisYear(year);
|
|
LocalDateTime lastDayOfYear = DateUtils.getLastDayOfThisYear(year);
|
|
Integer lastWeek = lastDayOfYear.get(weekFields.weekOfYear());
|
|
Integer lastWeek = lastDayOfYear.get(weekFields.weekOfYear());
|
|
return getLastDayOfWeek(year, lastWeek);
|
|
return getLastDayOfWeek(year, lastWeek);
|
|
@@ -357,11 +359,12 @@ public class DateUtils {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取两个时间点的月份差
|
|
* 获取两个时间点的月份差
|
|
|
|
+ *
|
|
* @param dt1 第一个时间点 前面的时间
|
|
* @param dt1 第一个时间点 前面的时间
|
|
* @param dt2 第二个时间点 后面的时间
|
|
* @param dt2 第二个时间点 后面的时间
|
|
* @return int,即需求的月数差
|
|
* @return int,即需求的月数差
|
|
*/
|
|
*/
|
|
- public static int monthDiff(LocalDate dt1,LocalDate dt2){
|
|
|
|
|
|
+ public static int monthDiff(LocalDate dt1, LocalDate dt2) {
|
|
//获取第一个时间点的月份
|
|
//获取第一个时间点的月份
|
|
int month1 = dt1.getMonthValue();
|
|
int month1 = dt1.getMonthValue();
|
|
//获取第一个时间点的年份
|
|
//获取第一个时间点的年份
|
|
@@ -371,7 +374,7 @@ public class DateUtils {
|
|
//获取第二个时间点的年份
|
|
//获取第二个时间点的年份
|
|
int year2 = dt2.getYear();
|
|
int year2 = dt2.getYear();
|
|
//返回两个时间点的月数差
|
|
//返回两个时间点的月数差
|
|
- return (year2 - year1) *12 + (month2 - month1);
|
|
|
|
|
|
+ return (year2 - year1) * 12 + (month2 - month1);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -396,50 +399,54 @@ public class DateUtils {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 相差分钟数
|
|
* 相差分钟数
|
|
|
|
+ *
|
|
* @param startTime
|
|
* @param startTime
|
|
* @param endTime
|
|
* @param endTime
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static long getDurationMinutes(LocalDateTime startTime, LocalDateTime endTime ){
|
|
|
|
- Duration duration = Duration.between(startTime,endTime);
|
|
|
|
|
|
+ public static long getDurationMinutes(LocalDateTime startTime, LocalDateTime endTime) {
|
|
|
|
+ Duration duration = Duration.between(startTime, endTime);
|
|
return duration.toMinutes();
|
|
return duration.toMinutes();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 相差分钟数:字符串格式
|
|
* 相差分钟数:字符串格式
|
|
|
|
+ *
|
|
* @param startTime
|
|
* @param startTime
|
|
* @param endTime
|
|
* @param endTime
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static String getDurationMinutesStr(LocalDateTime startTime, LocalDateTime endTime ){
|
|
|
|
- return String.valueOf(getDurationMinutes(startTime,endTime ));
|
|
|
|
|
|
+ public static String getDurationMinutesStr(LocalDateTime startTime, LocalDateTime endTime) {
|
|
|
|
+ return String.valueOf(getDurationMinutes(startTime, endTime));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 相差小时数
|
|
* 相差小时数
|
|
|
|
+ *
|
|
* @param startTime
|
|
* @param startTime
|
|
* @param endTime
|
|
* @param endTime
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static double getDurationHours(LocalDateTime startTime, LocalDateTime endTime ){
|
|
|
|
- Duration duration = Duration.between(startTime,endTime);
|
|
|
|
|
|
+ public static double getDurationHours(LocalDateTime startTime, LocalDateTime endTime) {
|
|
|
|
+ Duration duration = Duration.between(startTime, endTime);
|
|
long minitues = duration.toMinutes();
|
|
long minitues = duration.toMinutes();
|
|
- double hours = BigDecimalUtil.round(minitues/60.0, 2);
|
|
|
|
|
|
+ double hours = BigDecimalUtil.round(minitues / 60.0, 2);
|
|
return hours;
|
|
return hours;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 相差小时数:字符串
|
|
* 相差小时数:字符串
|
|
|
|
+ *
|
|
* @param startTime
|
|
* @param startTime
|
|
* @param endTime
|
|
* @param endTime
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static String getDurationHoursStr(LocalDateTime startTime, LocalDateTime endTime ){
|
|
|
|
- Duration duration = Duration.between(startTime,endTime);
|
|
|
|
- return String.valueOf(getDurationHours(startTime,endTime ));
|
|
|
|
|
|
+ public static String getDurationHoursStr(LocalDateTime startTime, LocalDateTime endTime) {
|
|
|
|
+ Duration duration = Duration.between(startTime, endTime);
|
|
|
|
+ return String.valueOf(getDurationHours(startTime, endTime));
|
|
}
|
|
}
|
|
|
|
|
|
- public static String dateDiff(LocalDateTime end, LocalDateTime now){
|
|
|
|
|
|
+ public static String dateDiff(LocalDateTime end, LocalDateTime now) {
|
|
//获取秒数
|
|
//获取秒数
|
|
long nowSecond = now.toEpochSecond(ZoneOffset.ofHours(0));
|
|
long nowSecond = now.toEpochSecond(ZoneOffset.ofHours(0));
|
|
long endSecond = end.toEpochSecond(ZoneOffset.ofHours(0));
|
|
long endSecond = end.toEpochSecond(ZoneOffset.ofHours(0));
|
|
@@ -453,7 +460,7 @@ public class DateUtils {
|
|
long h = absSeconds / 60 / 60 % 24;
|
|
long h = absSeconds / 60 / 60 % 24;
|
|
//获取天数
|
|
//获取天数
|
|
long d = absSeconds / 60 / 60 / 24;
|
|
long d = absSeconds / 60 / 60 / 24;
|
|
- return d+"天"+h+"小时"+m+"分钟"+s+"秒";
|
|
|
|
|
|
+ return d + "天" + h + "小时" + m + "分钟" + s + "秒";
|
|
}
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
@@ -484,17 +491,17 @@ public class DateUtils {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static List<Map<String, LocalDateTime>> getMonthStartAndEndByYear(int year, int month) {
|
|
public static List<Map<String, LocalDateTime>> getMonthStartAndEndByYear(int year, int month) {
|
|
- List<Map<String, LocalDateTime>> monthStartAndEndList = new ArrayList<Map<String,LocalDateTime>>();
|
|
|
|
|
|
+ List<Map<String, LocalDateTime>> monthStartAndEndList = new ArrayList<Map<String, LocalDateTime>>();
|
|
// 每年的 一月一号,零时零分零秒
|
|
// 每年的 一月一号,零时零分零秒
|
|
- for(int i = 1;i<month;i++){
|
|
|
|
|
|
+ for (int i = 1; i < month; i++) {
|
|
Map<String, LocalDateTime> dateTimeMap = new HashMap<String, LocalDateTime>();
|
|
Map<String, LocalDateTime> dateTimeMap = new HashMap<String, LocalDateTime>();
|
|
LocalDateTime searchStartTimeMonth = getFirstDayOfMonth(year, i).plusDays(-1);
|
|
LocalDateTime searchStartTimeMonth = getFirstDayOfMonth(year, i).plusDays(-1);
|
|
LocalDateTime searchEndTimeMonth = getLastDayOfMonth(year, i).plusDays(1);
|
|
LocalDateTime searchEndTimeMonth = getLastDayOfMonth(year, i).plusDays(1);
|
|
dateTimeMap.put("searchStartTimeMonth", searchStartTimeMonth);
|
|
dateTimeMap.put("searchStartTimeMonth", searchStartTimeMonth);
|
|
- dateTimeMap.put("searchEndTimeMonth",searchEndTimeMonth);
|
|
|
|
|
|
+ dateTimeMap.put("searchEndTimeMonth", searchEndTimeMonth);
|
|
monthStartAndEndList.add(dateTimeMap);
|
|
monthStartAndEndList.add(dateTimeMap);
|
|
}
|
|
}
|
|
- return monthStartAndEndList;
|
|
|
|
|
|
+ return monthStartAndEndList;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -505,23 +512,23 @@ public class DateUtils {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static List<Map<String, LocalDateTime>> getYearStartAndEndByYear(int startYear, int endYear) {
|
|
public static List<Map<String, LocalDateTime>> getYearStartAndEndByYear(int startYear, int endYear) {
|
|
- if(startYear < 2020){
|
|
|
|
|
|
+ if (startYear < 2020) {
|
|
startYear = 2020;
|
|
startYear = 2020;
|
|
}
|
|
}
|
|
- if(endYear == 2021){
|
|
|
|
|
|
+ if (endYear == 2021) {
|
|
endYear = LocalDate.now().getYear();
|
|
endYear = LocalDate.now().getYear();
|
|
}
|
|
}
|
|
- List<Map<String, LocalDateTime>> startAndEndList = new ArrayList<Map<String,LocalDateTime>>();
|
|
|
|
|
|
+ List<Map<String, LocalDateTime>> startAndEndList = new ArrayList<Map<String, LocalDateTime>>();
|
|
// 每年的 一月一号,零时零分零秒
|
|
// 每年的 一月一号,零时零分零秒
|
|
- for(int i = startYear;i<=endYear;i++){
|
|
|
|
|
|
+ for (int i = startYear; i <= endYear; i++) {
|
|
Map<String, LocalDateTime> dateTimeMap = new HashMap<String, LocalDateTime>();
|
|
Map<String, LocalDateTime> dateTimeMap = new HashMap<String, LocalDateTime>();
|
|
LocalDateTime searchStartTimeMonth = getFirstDayOfThisYear(i);
|
|
LocalDateTime searchStartTimeMonth = getFirstDayOfThisYear(i);
|
|
LocalDateTime searchEndTimeMonth = getLastDayOfThisYear(i);
|
|
LocalDateTime searchEndTimeMonth = getLastDayOfThisYear(i);
|
|
dateTimeMap.put("searchStartTime", searchStartTimeMonth);
|
|
dateTimeMap.put("searchStartTime", searchStartTimeMonth);
|
|
- dateTimeMap.put("searchEndTime",searchEndTimeMonth);
|
|
|
|
|
|
+ dateTimeMap.put("searchEndTime", searchEndTimeMonth);
|
|
startAndEndList.add(dateTimeMap);
|
|
startAndEndList.add(dateTimeMap);
|
|
}
|
|
}
|
|
- return startAndEndList;
|
|
|
|
|
|
+ return startAndEndList;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -532,18 +539,18 @@ public class DateUtils {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static List<Map<String, LocalDateTime>> getMonthStartAndEndByYear(LocalDate startMonth, LocalDate endMonth) {
|
|
public static List<Map<String, LocalDateTime>> getMonthStartAndEndByYear(LocalDate startMonth, LocalDate endMonth) {
|
|
- List<Map<String, LocalDateTime>> monthStartAndEndList = new ArrayList<Map<String,LocalDateTime>>();
|
|
|
|
|
|
+ List<Map<String, LocalDateTime>> monthStartAndEndList = new ArrayList<Map<String, LocalDateTime>>();
|
|
int month = DateUtils.monthDiff(startMonth, endMonth);
|
|
int month = DateUtils.monthDiff(startMonth, endMonth);
|
|
- for(int i = 0;i<=month;i++){
|
|
|
|
|
|
+ for (int i = 0; i <= month; i++) {
|
|
LocalDate date = DateUtils.plus(startMonth, i, ChronoUnit.MONTHS);
|
|
LocalDate date = DateUtils.plus(startMonth, i, ChronoUnit.MONTHS);
|
|
Map<String, LocalDateTime> dateTimeMap = new HashMap<String, LocalDateTime>();
|
|
Map<String, LocalDateTime> dateTimeMap = new HashMap<String, LocalDateTime>();
|
|
LocalDateTime searchStartTimeMonth = getFirstDayOfMonth(date);
|
|
LocalDateTime searchStartTimeMonth = getFirstDayOfMonth(date);
|
|
LocalDateTime searchEndTimeMonth = getLastDayOfMonth(date);
|
|
LocalDateTime searchEndTimeMonth = getLastDayOfMonth(date);
|
|
dateTimeMap.put("searchStartTimeMonth", searchStartTimeMonth);
|
|
dateTimeMap.put("searchStartTimeMonth", searchStartTimeMonth);
|
|
- dateTimeMap.put("searchEndTimeMonth",searchEndTimeMonth);
|
|
|
|
|
|
+ dateTimeMap.put("searchEndTimeMonth", searchEndTimeMonth);
|
|
monthStartAndEndList.add(dateTimeMap);
|
|
monthStartAndEndList.add(dateTimeMap);
|
|
}
|
|
}
|
|
- return monthStartAndEndList;
|
|
|
|
|
|
+ return monthStartAndEndList;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -553,8 +560,8 @@ public class DateUtils {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static List<Map<String, LocalDateTime>> getWeekStartAndEndByYear(int year) {
|
|
public static List<Map<String, LocalDateTime>> getWeekStartAndEndByYear(int year) {
|
|
- List<Map<String, LocalDateTime>> weekStartAndEndList = new ArrayList<Map<String,LocalDateTime>>();
|
|
|
|
- WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY,1);
|
|
|
|
|
|
+ List<Map<String, LocalDateTime>> weekStartAndEndList = new ArrayList<Map<String, LocalDateTime>>();
|
|
|
|
+ WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1);
|
|
LocalDate now = LocalDate.now();
|
|
LocalDate now = LocalDate.now();
|
|
LocalDateTime firstDayOfYear = DateUtils.getFirstDayOfThisYear(year);
|
|
LocalDateTime firstDayOfYear = DateUtils.getFirstDayOfThisYear(year);
|
|
LocalDateTime lastDayOfYear = DateUtils.getLastDayOfThisYear(year);
|
|
LocalDateTime lastDayOfYear = DateUtils.getLastDayOfThisYear(year);
|
|
@@ -562,31 +569,31 @@ public class DateUtils {
|
|
Integer firstWeek = firstDayOfYear.get(weekFields.weekOfYear());
|
|
Integer firstWeek = firstDayOfYear.get(weekFields.weekOfYear());
|
|
Integer lastWeek = lastDayOfYear.get(weekFields.weekOfYear());
|
|
Integer lastWeek = lastDayOfYear.get(weekFields.weekOfYear());
|
|
// 每年的 一月一号,零时零分零秒
|
|
// 每年的 一月一号,零时零分零秒
|
|
- for(int i = firstWeek;i<lastWeek;i++){
|
|
|
|
|
|
+ for (int i = firstWeek; i < lastWeek; i++) {
|
|
Map<String, LocalDateTime> dateTimeMap = new HashMap<String, LocalDateTime>();
|
|
Map<String, LocalDateTime> dateTimeMap = new HashMap<String, LocalDateTime>();
|
|
LocalDateTime searchStartTimeWeek = getFirstDayOfWeek(year, i);
|
|
LocalDateTime searchStartTimeWeek = getFirstDayOfWeek(year, i);
|
|
LocalDateTime searchEndTimeWeek = getLastDayOfWeek(year, i);
|
|
LocalDateTime searchEndTimeWeek = getLastDayOfWeek(year, i);
|
|
dateTimeMap.put("searchStartTimeWeek", searchStartTimeWeek);
|
|
dateTimeMap.put("searchStartTimeWeek", searchStartTimeWeek);
|
|
- dateTimeMap.put("searchEndTimeWeek",searchEndTimeWeek);
|
|
|
|
|
|
+ dateTimeMap.put("searchEndTimeWeek", searchEndTimeWeek);
|
|
weekStartAndEndList.add(dateTimeMap);
|
|
weekStartAndEndList.add(dateTimeMap);
|
|
}
|
|
}
|
|
- return weekStartAndEndList;
|
|
|
|
|
|
+ return weekStartAndEndList;
|
|
}
|
|
}
|
|
|
|
|
|
- public static List<LocalDateTime> currentWeek(){
|
|
|
|
|
|
+ public static List<LocalDateTime> currentWeek() {
|
|
List<LocalDateTime> list = new ArrayList<>();
|
|
List<LocalDateTime> list = new ArrayList<>();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
- for(int i=-6;i<0;i++){
|
|
|
|
|
|
+ for (int i = -6; i < 0; i++) {
|
|
list.add(now.plusDays(i));
|
|
list.add(now.plusDays(i));
|
|
}
|
|
}
|
|
list.add(now);
|
|
list.add(now);
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|
|
- public static List<LocalDate> currentWeekDate(){
|
|
|
|
|
|
+ public static List<LocalDate> currentWeekDate() {
|
|
List<LocalDate> list = new ArrayList<>();
|
|
List<LocalDate> list = new ArrayList<>();
|
|
LocalDate now = LocalDate.now();
|
|
LocalDate now = LocalDate.now();
|
|
- for(int i=-6;i<0;i++){
|
|
|
|
|
|
+ for (int i = -6; i < 0; i++) {
|
|
list.add(now.plusDays(i));
|
|
list.add(now.plusDays(i));
|
|
}
|
|
}
|
|
list.add(now);
|
|
list.add(now);
|
|
@@ -616,6 +623,23 @@ public class DateUtils {
|
|
return ldt;
|
|
return ldt;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 根据
|
|
|
|
+ */
|
|
|
|
+ public static String getChineseWeekName(DayOfWeek dayOfWeek) {
|
|
|
|
+ if(dayOfWeek == null){
|
|
|
|
+ return "星期一";
|
|
|
|
+ }
|
|
|
|
+ String[][] strArray = {{"MONDAY", "星期一"}, {"TUESDAY", "星期二"}, {"WEDNESDAY", "星期三"}, {"THURSDAY", "星期四"}, {"FRIDAY", "星期五"}, {"SATURDAY", "星期六"}, {"SUNDAY", "星期日"}};
|
|
|
|
+ String k = String.valueOf(dayOfWeek);
|
|
|
|
+ for (int i = 0; i < strArray.length; i++) {
|
|
|
|
+ if (k.equals(strArray[i][0])) {
|
|
|
|
+ k = strArray[i][1];
|
|
|
|
+ return k;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ throw new BusinessException("未知dayOfWeek" + String.valueOf(dayOfWeek));
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|