java - SimpleDateFormat: Unparseable date when I try parse month: MMM dd, yyyy
问题描述
I try to parse string do the Date format, but get Unparserable exception:
public void roundTest() throws ParseException {
String pattern = "MMM dd, yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
String from = "Jul 01, 2021";
Date result = sdf.parse(from);
}
The same for java.time
package:
public void roundTest() throws ParseException {
String from = "Jul 01, 2021";
String pattern = "MMM dd, yyyy";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
System.out.println(LocalDate.parse(from, formatter));
}
Error: "java.time.format.DateTimeParseException: Text 'Jul 01, 2021' could not be parsed at index 0"
Where the error?
解决方案
推荐阅读
- java - 导入静态是一个好习惯吗?
- apache-unomi - 如何在 Apache Unomi 条件下使用运算符 OR
- python - Kivy,奇数和不一致的球运动(动画)
- r - RSelenium 将在单独运行每一行时运行,但在代码块中运行时不会运行
- flutter - 如何更改 TextFormField 线条颜色?
- mysql - Mysql查询:在一行中组合多行,按日期分组
- ssl - 是否可以在网页上下文中信任证书?
- powerbi - 如何在 Power Query 中向上移动空单元格?
- iframe - 内容安全策略问题...iframe 和内联样式
- arrays - 是否可以在此 c 代码中使用数组名称指针进行输入?