产值
This commit is contained in:
@ -148,6 +148,23 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定格式的日期时间字符串转换为 LocalDate 对象
|
||||
*
|
||||
* @param format 要解析的日期时间格式,例如"YYYY-MM-DD HH:MM:SS"
|
||||
* @param ts 要解析的日期时间字符串
|
||||
* @return 解析后的 Date 对象
|
||||
* @throws RuntimeException 如果解析过程中发生异常
|
||||
*/
|
||||
public static LocalDate parseLocalDateTime(final FormatsType format, final String ts) {
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format.getTimeFormat());
|
||||
return LocalDate.parse(ts, formatter);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转换为日期对象
|
||||
*
|
||||
@ -254,6 +271,16 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
return Date.from(zdt.toInstant());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Date 对象转换为 LocalDate 对象
|
||||
*
|
||||
* @param temporalAccessor 要转换的 Date 对象
|
||||
* @return 转换后的 LocalDate 对象
|
||||
*/
|
||||
public static LocalDate toLocalDate(Date temporalAccessor) {
|
||||
return temporalAccessor.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验日期范围
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user