尝试格式化日期时出现此错误时间。 这是代码段。
private LocalDate expirationDate;
public static String convertIntlToStandard(String dateTpChange) {
if(StringUtils.isNotBlank(dateTpChange)) {
DateTimeFormatter oldformatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate formatDateTime = LocalDate.parse(dateTpChange, oldformatter);
DateTimeFormatter newformatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
return formatDateTime.format(newformatter);
} else {
return dateTpChange;
}
}
boPrescriptionResponse.setExpirationDate(LocalDate.parse(DateUtils.convertIntlToStandard(boPrescription.getExpirationDate().toString())));
java.time.format.DateTimeParseException:无法在索引0处解析文本'06 / 05/2019'
答案 0 :(得分:0)
您好像切换了oldformatter
和newformatter
:
public static String convertIntlToStandard(String dateTpChange) {
if(StringUtils.isNotBlank(dateTpChange)) {
DateTimeFormatter oldformatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
LocalDate formatDateTime = LocalDate.parse(dateTpChange, oldformatter);
DateTimeFormatter newformatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return formatDateTime.format(newformatter);
} else {
return dateTpChange;
}
}