|
@@ -1,7 +1,5 @@
|
|
|
package com.huashe.park.common;
|
|
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.Duration;
|
|
@@ -18,6 +16,8 @@ import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
/**
|
|
|
* The type Date time util.
|
|
|
*
|
|
@@ -49,7 +49,7 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Parse date date.
|
|
|
*
|
|
|
- * @param dateString the date string
|
|
|
+ * @param dateString the date string
|
|
|
* @param formatRegex the format regex
|
|
|
* @return the date
|
|
|
* @author chen.cheng
|
|
@@ -57,7 +57,7 @@ public class DateTimeUtil {
|
|
|
public static Date parseDate(String dateString, String formatRegex) {
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatRegex);
|
|
|
LocalDateTime dateTime = LocalDateTime.parse(dateString, formatter);
|
|
|
- Instant instant = dateTime.atZone(ZoneId.of("GMT+08:00")).toInstant();
|
|
|
+ Instant instant = dateTime.atZone(ZoneId.systemDefault()).toInstant();
|
|
|
return Date.from(instant);
|
|
|
}
|
|
|
|
|
@@ -70,7 +70,7 @@ public class DateTimeUtil {
|
|
|
*/
|
|
|
public static Date minusDay(Long dayNum) {
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
- Instant instant = now.atZone(ZoneId.of("GMT+08:00")).toInstant();
|
|
|
+ Instant instant = now.atZone(ZoneId.systemDefault()).toInstant();
|
|
|
return Date.from(instant);
|
|
|
}
|
|
|
|
|
@@ -78,7 +78,7 @@ public class DateTimeUtil {
|
|
|
* Parse date string.
|
|
|
*
|
|
|
* @param localDateTime the local date time
|
|
|
- * @param formatRegex the format regex
|
|
|
+ * @param formatRegex the format regex
|
|
|
* @return the string
|
|
|
* @author chen.cheng
|
|
|
*/
|
|
@@ -90,7 +90,7 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Parse date string.
|
|
|
*
|
|
|
- * @param localDate the local date
|
|
|
+ * @param localDate the local date
|
|
|
* @param formatRegex the format regex
|
|
|
* @return the string
|
|
|
* @author chen.cheng
|
|
@@ -130,11 +130,10 @@ public class DateTimeUtil {
|
|
|
return getDateFromMills(mills, DateFormatter.yyyy_MM_dd_HHmmss);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Parse local date local date time.
|
|
|
*
|
|
|
- * @param dateString the date string
|
|
|
+ * @param dateString the date string
|
|
|
* @param formatRegex the format regex
|
|
|
* @return the local date time
|
|
|
* @author chen.cheng
|
|
@@ -156,7 +155,7 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Parse local date local date.
|
|
|
*
|
|
|
- * @param dateString the date string
|
|
|
+ * @param dateString the date string
|
|
|
* @param formatRegex the format regex
|
|
|
* @return the local date
|
|
|
* @author chen.cheng
|
|
@@ -170,7 +169,7 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Parse date string string.
|
|
|
*
|
|
|
- * @param dateString the date string
|
|
|
+ * @param dateString the date string
|
|
|
* @param formatRegex the format regex
|
|
|
* @return the string
|
|
|
* @author chen.cheng
|
|
@@ -184,9 +183,9 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Parse date string string.
|
|
|
*
|
|
|
- * @param dateString the date string
|
|
|
+ * @param dateString the date string
|
|
|
* @param srcFormatRegex the src format regex
|
|
|
- * @param formatRegex the format regex
|
|
|
+ * @param formatRegex the format regex
|
|
|
* @return the string
|
|
|
* @author chen.cheng
|
|
|
*/
|
|
@@ -199,9 +198,9 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Parse short date string string(yyyyMMdd).
|
|
|
*
|
|
|
- * @param dateString the date string
|
|
|
+ * @param dateString the date string
|
|
|
* @param srcFormatRegex the src format regex
|
|
|
- * @param formatRegex the format regex
|
|
|
+ * @param formatRegex the format regex
|
|
|
* @return the string
|
|
|
* @author chen.cheng
|
|
|
*/
|
|
@@ -215,8 +214,8 @@ public class DateTimeUtil {
|
|
|
* Days of range list.
|
|
|
*
|
|
|
* @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
|
|
|
* @author chen.cheng
|
|
|
*/
|
|
@@ -227,7 +226,7 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Minus month string.
|
|
|
*
|
|
|
- * @param monthNum the month num
|
|
|
+ * @param monthNum the month num
|
|
|
* @param formatRegx the format regx
|
|
|
* @return the string
|
|
|
* @author chen.cheng
|
|
@@ -242,7 +241,7 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Minus month string
|
|
|
*
|
|
|
- * @param monthNum month num
|
|
|
+ * @param monthNum month num
|
|
|
* @param formatRegx format regx
|
|
|
* @return the string
|
|
|
* @author chen.cheng
|
|
@@ -265,7 +264,7 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Minus month string.
|
|
|
*
|
|
|
- * @param monthNum the month num
|
|
|
+ * @param monthNum the month num
|
|
|
* @param formatRegx the format regx
|
|
|
* @return the string
|
|
|
* @author chen.cheng
|
|
@@ -280,9 +279,9 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Date minus month string
|
|
|
*
|
|
|
- * @param date date
|
|
|
+ * @param date date
|
|
|
* @param formatRegx format regx
|
|
|
- * @param monthNum month num
|
|
|
+ * @param monthNum month num
|
|
|
* @return the string
|
|
|
* @author chen.cheng
|
|
|
*/
|
|
@@ -293,10 +292,10 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Date minus month string
|
|
|
*
|
|
|
- * @param date date
|
|
|
+ * @param date date
|
|
|
* @param srcFormatRegx src format regx
|
|
|
- * @param formatRegx format regx
|
|
|
- * @param monthNum month num
|
|
|
+ * @param formatRegx format regx
|
|
|
+ * @param monthNum month num
|
|
|
* @return the string
|
|
|
* @author chen.cheng
|
|
|
*/
|
|
@@ -310,7 +309,7 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Minus day string.
|
|
|
*
|
|
|
- * @param dayNum the day num
|
|
|
+ * @param dayNum the day num
|
|
|
* @param formatRegx the format regx
|
|
|
* @return the string
|
|
|
* @author chen.cheng
|
|
@@ -325,9 +324,9 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* 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
|
|
|
* @return the list
|
|
|
* @author chen.cheng
|
|
@@ -367,8 +366,8 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* 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
|
|
|
* @return the list
|
|
|
* @author chen.cheng
|
|
@@ -389,7 +388,7 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Gets time step of time index.
|
|
|
*
|
|
|
- * @param tp the tp
|
|
|
+ * @param tp the tp
|
|
|
* @param gap the gap (now + gap minutes)
|
|
|
* @return the time step of time index
|
|
|
* @author chen.cheng
|
|
@@ -401,24 +400,24 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Get time step index of now integer.
|
|
|
*
|
|
|
- * @param tp the tp
|
|
|
+ * @param tp the tp
|
|
|
* @param toDateTime the to date time
|
|
|
* @return the integer
|
|
|
* @author chen.cheng
|
|
|
*/
|
|
|
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);
|
|
|
double minutes = duration.toMinutes();
|
|
|
return (int) Math.floor(minutes / tp);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Gets time from step index. tp is min the format hh:mm:00
|
|
|
*
|
|
|
* @param stepIndex the step index
|
|
|
- * @param tp the tp
|
|
|
+ * @param tp the tp
|
|
|
* @return the time from step index
|
|
|
* @author chen.cheng
|
|
|
*/
|
|
@@ -433,7 +432,7 @@ public class DateTimeUtil {
|
|
|
* Gets time from step index with out second.
|
|
|
*
|
|
|
* @param stepIndex the step index
|
|
|
- * @param tp the tp
|
|
|
+ * @param tp the tp
|
|
|
* @return the time from step index with out second
|
|
|
* @author chen.cheng
|
|
|
*/
|
|
@@ -447,7 +446,7 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Gets day of week.
|
|
|
*
|
|
|
- * @param date the date
|
|
|
+ * @param date the date
|
|
|
* @param paramFormatter the param formatter
|
|
|
* @return the day of week
|
|
|
* @author chen.cheng
|
|
@@ -502,7 +501,7 @@ public class DateTimeUtil {
|
|
|
/**
|
|
|
* Cal week of year integer.
|
|
|
*
|
|
|
- * @param date the date
|
|
|
+ * @param date the date
|
|
|
* @param paramFormatter the param formatter
|
|
|
* @return the integer
|
|
|
* @author chen.cheng
|
|
@@ -550,7 +549,9 @@ public class DateTimeUtil {
|
|
|
firstTime = firstTime.plusDays(-(weekIndex * 7L));
|
|
|
// 结束时间
|
|
|
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) {
|
|
@@ -599,7 +600,6 @@ public class DateTimeUtil {
|
|
|
System.out.println(DateTimeUtil.getStepIndexFromMills(10, System.currentTimeMillis()));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* The interface Date formatter.
|
|
|
*
|