|
@@ -49,7 +49,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Parse date date.
|
|
* Parse date date.
|
|
*
|
|
*
|
|
- * @param dateString the date string
|
|
|
|
|
|
+ * @param dateString the date string
|
|
* @param formatRegex the format regex
|
|
* @param formatRegex the format regex
|
|
* @return the date
|
|
* @return the date
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -78,7 +78,7 @@ public class DateTimeUtil {
|
|
* Parse date string.
|
|
* Parse date string.
|
|
*
|
|
*
|
|
* @param localDateTime the local date time
|
|
* @param localDateTime the local date time
|
|
- * @param formatRegex the format regex
|
|
|
|
|
|
+ * @param formatRegex the format regex
|
|
* @return the string
|
|
* @return the string
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
*/
|
|
*/
|
|
@@ -90,7 +90,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Parse date string.
|
|
* Parse date string.
|
|
*
|
|
*
|
|
- * @param localDate the local date
|
|
|
|
|
|
+ * @param localDate the local date
|
|
* @param formatRegex the format regex
|
|
* @param formatRegex the format regex
|
|
* @return the string
|
|
* @return the string
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -116,7 +116,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Parse local date local date time.
|
|
* Parse local date local date time.
|
|
*
|
|
*
|
|
- * @param dateString the date string
|
|
|
|
|
|
+ * @param dateString the date string
|
|
* @param formatRegex the format regex
|
|
* @param formatRegex the format regex
|
|
* @return the local date time
|
|
* @return the local date time
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -130,7 +130,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Parse local date local date.
|
|
* Parse local date local date.
|
|
*
|
|
*
|
|
- * @param dateString the date string
|
|
|
|
|
|
+ * @param dateString the date string
|
|
* @param formatRegex the format regex
|
|
* @param formatRegex the format regex
|
|
* @return the local date
|
|
* @return the local date
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -144,7 +144,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Parse date string string.
|
|
* Parse date string string.
|
|
*
|
|
*
|
|
- * @param dateString the date string
|
|
|
|
|
|
+ * @param dateString the date string
|
|
* @param formatRegex the format regex
|
|
* @param formatRegex the format regex
|
|
* @return the string
|
|
* @return the string
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -158,9 +158,9 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Parse date string string.
|
|
* Parse date string string.
|
|
*
|
|
*
|
|
- * @param dateString the date string
|
|
|
|
|
|
+ * @param dateString the date string
|
|
* @param srcFormatRegex the src format regex
|
|
* @param srcFormatRegex the src format regex
|
|
- * @param formatRegex the format regex
|
|
|
|
|
|
+ * @param formatRegex the format regex
|
|
* @return the string
|
|
* @return the string
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
*/
|
|
*/
|
|
@@ -173,9 +173,9 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Parse short date string string(yyyyMMdd).
|
|
* Parse short date string string(yyyyMMdd).
|
|
*
|
|
*
|
|
- * @param dateString the date string
|
|
|
|
|
|
+ * @param dateString the date string
|
|
* @param srcFormatRegex the src format regex
|
|
* @param srcFormatRegex the src format regex
|
|
- * @param formatRegex the format regex
|
|
|
|
|
|
+ * @param formatRegex the format regex
|
|
* @return the string
|
|
* @return the string
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
*/
|
|
*/
|
|
@@ -189,8 +189,8 @@ public class DateTimeUtil {
|
|
* Days of range list.
|
|
* Days of range list.
|
|
*
|
|
*
|
|
* @param startDate the start date
|
|
* @param startDate the start date
|
|
- * @param endDate the end date DateTimeUtil.daysOfRange("2020-05-06",
|
|
|
|
- * "2020-09-02",DateFormatter.yyyy_MM_dd,DateFormatter.yyyyMMdd)
|
|
|
|
|
|
+ * @param endDate the end date DateTimeUtil.daysOfRange("2020-05-06",
|
|
|
|
+ * "2020-09-02",DateFormatter.yyyy_MM_dd,DateFormatter.yyyyMMdd)
|
|
* @return the list
|
|
* @return the list
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
*/
|
|
*/
|
|
@@ -201,7 +201,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Minus month string.
|
|
* Minus month string.
|
|
*
|
|
*
|
|
- * @param monthNum the month num
|
|
|
|
|
|
+ * @param monthNum the month num
|
|
* @param formatRegx the format regx
|
|
* @param formatRegx the format regx
|
|
* @return the string
|
|
* @return the string
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -216,7 +216,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Minus month string
|
|
* Minus month string
|
|
*
|
|
*
|
|
- * @param monthNum month num
|
|
|
|
|
|
+ * @param monthNum month num
|
|
* @param formatRegx format regx
|
|
* @param formatRegx format regx
|
|
* @return the string
|
|
* @return the string
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -239,7 +239,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Minus month string.
|
|
* Minus month string.
|
|
*
|
|
*
|
|
- * @param monthNum the month num
|
|
|
|
|
|
+ * @param monthNum the month num
|
|
* @param formatRegx the format regx
|
|
* @param formatRegx the format regx
|
|
* @return the string
|
|
* @return the string
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -254,9 +254,9 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Date minus month string
|
|
* Date minus month string
|
|
*
|
|
*
|
|
- * @param date date
|
|
|
|
|
|
+ * @param date date
|
|
* @param formatRegx format regx
|
|
* @param formatRegx format regx
|
|
- * @param monthNum month num
|
|
|
|
|
|
+ * @param monthNum month num
|
|
* @return the string
|
|
* @return the string
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
*/
|
|
*/
|
|
@@ -267,10 +267,10 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Date minus month string
|
|
* Date minus month string
|
|
*
|
|
*
|
|
- * @param date date
|
|
|
|
|
|
+ * @param date date
|
|
* @param srcFormatRegx src format regx
|
|
* @param srcFormatRegx src format regx
|
|
- * @param formatRegx format regx
|
|
|
|
- * @param monthNum month num
|
|
|
|
|
|
+ * @param formatRegx format regx
|
|
|
|
+ * @param monthNum month num
|
|
* @return the string
|
|
* @return the string
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
*/
|
|
*/
|
|
@@ -284,7 +284,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Minus day string.
|
|
* Minus day string.
|
|
*
|
|
*
|
|
- * @param dayNum the day num
|
|
|
|
|
|
+ * @param dayNum the day num
|
|
* @param formatRegx the format regx
|
|
* @param formatRegx the format regx
|
|
* @return the string
|
|
* @return the string
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -299,9 +299,9 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Days of range list.
|
|
* Days of range list.
|
|
*
|
|
*
|
|
- * @param startDate the start date
|
|
|
|
- * @param endDate the end date
|
|
|
|
- * @param paramFormat the param format
|
|
|
|
|
|
+ * @param startDate the start date
|
|
|
|
+ * @param endDate the end date
|
|
|
|
+ * @param paramFormat the param format
|
|
* @param resultFormat the result format
|
|
* @param resultFormat the result format
|
|
* @return the list
|
|
* @return the list
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -341,8 +341,8 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Days of range list.
|
|
* Days of range list.
|
|
*
|
|
*
|
|
- * @param startDate the start date
|
|
|
|
- * @param endDate the end date
|
|
|
|
|
|
+ * @param startDate the start date
|
|
|
|
+ * @param endDate the end date
|
|
* @param paramFormat the param format
|
|
* @param paramFormat the param format
|
|
* @return the list
|
|
* @return the list
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -363,7 +363,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Gets time step of time index.
|
|
* Gets time step of time index.
|
|
*
|
|
*
|
|
- * @param tp the tp
|
|
|
|
|
|
+ * @param tp the tp
|
|
* @param gap the gap (now + gap minutes)
|
|
* @param gap the gap (now + gap minutes)
|
|
* @return the time step of time index
|
|
* @return the time step of time index
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -375,13 +375,14 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Get time step index of now integer.
|
|
* Get time step index of now integer.
|
|
*
|
|
*
|
|
- * @param tp the tp
|
|
|
|
|
|
+ * @param tp the tp
|
|
* @param toDateTime the to date time
|
|
* @param toDateTime the to date time
|
|
* @return the integer
|
|
* @return the integer
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
*/
|
|
*/
|
|
public static int getTimeStepIndexOfNow(Integer tp, LocalDateTime toDateTime) {
|
|
public static int getTimeStepIndexOfNow(Integer tp, LocalDateTime toDateTime) {
|
|
- LocalDateTime zero = LocalDateTime.of(toDateTime.getYear(), toDateTime.getMonth(), toDateTime.getDayOfMonth(), 0, 0, 0);
|
|
|
|
|
|
+ LocalDateTime zero = LocalDateTime.of(toDateTime.getYear(), toDateTime.getMonth(), toDateTime.getDayOfMonth(),
|
|
|
|
+ 0, 0, 0);
|
|
Duration duration = Duration.between(zero, toDateTime);
|
|
Duration duration = Duration.between(zero, toDateTime);
|
|
double minutes = duration.toMinutes();
|
|
double minutes = duration.toMinutes();
|
|
return (int) Math.floor(minutes / tp);
|
|
return (int) Math.floor(minutes / tp);
|
|
@@ -391,7 +392,7 @@ public class DateTimeUtil {
|
|
* Gets time from step index. tp is min the format hh:mm:00
|
|
* Gets time from step index. tp is min the format hh:mm:00
|
|
*
|
|
*
|
|
* @param stepIndex the step index
|
|
* @param stepIndex the step index
|
|
- * @param tp the tp
|
|
|
|
|
|
+ * @param tp the tp
|
|
* @return the time from step index
|
|
* @return the time from step index
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
*/
|
|
*/
|
|
@@ -406,7 +407,7 @@ public class DateTimeUtil {
|
|
* Gets time from step index with out second.
|
|
* Gets time from step index with out second.
|
|
*
|
|
*
|
|
* @param stepIndex the step index
|
|
* @param stepIndex the step index
|
|
- * @param tp the tp
|
|
|
|
|
|
+ * @param tp the tp
|
|
* @return the time from step index with out second
|
|
* @return the time from step index with out second
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
*/
|
|
*/
|
|
@@ -420,7 +421,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Gets day of week.
|
|
* Gets day of week.
|
|
*
|
|
*
|
|
- * @param date the date
|
|
|
|
|
|
+ * @param date the date
|
|
* @param paramFormatter the param formatter
|
|
* @param paramFormatter the param formatter
|
|
* @return the day of week
|
|
* @return the day of week
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -475,7 +476,7 @@ public class DateTimeUtil {
|
|
/**
|
|
/**
|
|
* Cal week of year integer.
|
|
* Cal week of year integer.
|
|
*
|
|
*
|
|
- * @param date the date
|
|
|
|
|
|
+ * @param date the date
|
|
* @param paramFormatter the param formatter
|
|
* @param paramFormatter the param formatter
|
|
* @return the integer
|
|
* @return the integer
|
|
* @author chen.cheng
|
|
* @author chen.cheng
|
|
@@ -523,7 +524,9 @@ public class DateTimeUtil {
|
|
firstTime = firstTime.plusDays(-(weekIndex * 7L));
|
|
firstTime = firstTime.plusDays(-(weekIndex * 7L));
|
|
// 结束时间
|
|
// 结束时间
|
|
lastTime = lastTime.plusDays(-1);
|
|
lastTime = lastTime.plusDays(-1);
|
|
- return new String[]{firstTime.format(resultDateFormat), lastTime.format(resultDateFormat)};
|
|
|
|
|
|
+ return new String[] {
|
|
|
|
+ firstTime.format(resultDateFormat), lastTime.format(resultDateFormat)
|
|
|
|
+ };
|
|
}
|
|
}
|
|
|
|
|
|
public static String getFirstDayOfRecentYear(String dateFormat) {
|
|
public static String getFirstDayOfRecentYear(String dateFormat) {
|
|
@@ -534,7 +537,7 @@ public class DateTimeUtil {
|
|
int recentYear = today.getYear() - 1;
|
|
int recentYear = today.getYear() - 1;
|
|
|
|
|
|
// 使用 TemporalAdjusters 来找到近一年的第一天
|
|
// 使用 TemporalAdjusters 来找到近一年的第一天
|
|
- LocalDate localDate = LocalDate.of(recentYear, 1, 1).with(TemporalAdjusters.firstDayOfYear());
|
|
|
|
|
|
+ LocalDate localDate = LocalDate.of(recentYear, today.getMonth(), 1);
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
|
|
return localDate.format(formatter);
|
|
return localDate.format(formatter);
|
|
}
|
|
}
|
|
@@ -551,6 +554,7 @@ public class DateTimeUtil {
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
|
|
return localDate.format(formatter);
|
|
return localDate.format(formatter);
|
|
}
|
|
}
|
|
|
|
+
|
|
public static String getFirstDayOfRecentYear() {
|
|
public static String getFirstDayOfRecentYear() {
|
|
return getFirstDayOfRecentYear(DateFormatter.yyyy_MM_dd);
|
|
return getFirstDayOfRecentYear(DateFormatter.yyyy_MM_dd);
|
|
}
|
|
}
|