LocalDateTime localDateTime;
try {
localDateTime = LocalDateTime.parse(str, DateTimeFormatter.ofPattern(pattern));
} catch (Exception ex) {
ex.printStackTrace();
LocalDate localDate = parseLocalDate(str, pattern);
localDateTime = Objects.isNull(localDate) ? null : localDate.atStartOfDay();
}
return localDateTime;
}
/**
* desc :
* create_user : cheng
* create_date : 2019/5/27 19:30
*/
private LocalDate parseLocalDate(String str, String pattern) {
if (StringUtils.isAnyBlank(str, pattern)) {
return null;
}
LocalDate localDate = null;
try {
localDate = LocalDate.parse(str, DateTimeFormatter.ofPattern(pattern));
} catch (Exception ex) {
ex.printStackTrace();
}
return localDate;
}
标签:LocalDate,MM,pattern,dd,yyyy,ex,str,localDateTime,localDate
From: https://blog.51cto.com/u_16271212/8202222