Commit b285b4b8 authored by 李灿灿's avatar 李灿灿

字符串格式的日期转LocalDate工具类调整

parent 042086ce
......@@ -7,6 +7,7 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
......@@ -75,11 +76,14 @@ public class LocalDateUtil {
*/
public static LocalDate parseLocalDate(String strDate){
try {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(NORM_DATE_PATTERN, Locale.CHINA);
LocalDate localDate = LocalDate.parse(strDate, dateTimeFormatter);
return localDate;
if (isDate(strDate,NORM_DATE_PATTERN)){
DateFormat dateFormat = new SimpleDateFormat(NORM_DATE_PATTERN);
Date date = dateFormat.parse(strDate);
return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}
return null;
}catch (Exception e){
e.printStackTrace();
System.out.println("字符串格式的日期转LocalDate失败");
return null;
}
}
......@@ -337,6 +341,6 @@ public class LocalDateUtil {
}
public static void main(String[] args) {
System.out.println(isOverdueDate("2022-08-03"));
System.out.println(parseLocalDate("2022-8-3"));
}
}
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