SimpleDateFormat 中的非法模式字符 'O'
Illegal pattern character 'O' in SimpleDateFormatter
我收到了
java.lang.IllegalArgumentException: Illegal pattern character 'O'
java.text.SimpleDateFormat.compile(SimpleDateFormat.java:845)
执行这段代码时:
DateFormat format = new SimpleDateFormat("DD-MON-YY");
我该如何解决这个问题?
"DD-MON-YY"
不是有效的日期格式。尝试:
new SimpleDateFormat("dd-MMM-yy")
有关有效格式的详细信息,请参阅 the documentation。
您的日志不言自明,
java.lang.IllegalArgumentException: Illegal pattern character 'O'
java.text.SimpleDateFormat.compile(SimpleDateFormat.java:845)
java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:659)
阅读第一行本身。
SimplDateFormat 接受以下模式的一些示例。
new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z");
new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
new SimpleDateFormat("yyyy/MM/dd");
参考 - https://examples.javacodegeeks.com/core-java/text/java-dateformat-example/
您没有提供正确的日期格式。例如,您可以这样做:
new SimpleDateFormat("dd-MMM-yy")
但不是
new SimpleDateFormat("DD-MON-YY");
此错误是由于 Oracle 日期和时间格式说明符未被 SimpleDateFormat 完全支持。您应该更改此模式,或找到一种方法(实现一个函数)将其转换为 SimpleDateFormat 支持的模式。
我收到了
java.lang.IllegalArgumentException: Illegal pattern character 'O' java.text.SimpleDateFormat.compile(SimpleDateFormat.java:845)
执行这段代码时:
DateFormat format = new SimpleDateFormat("DD-MON-YY");
我该如何解决这个问题?
"DD-MON-YY"
不是有效的日期格式。尝试:
new SimpleDateFormat("dd-MMM-yy")
有关有效格式的详细信息,请参阅 the documentation。
您的日志不言自明,
java.lang.IllegalArgumentException: Illegal pattern character 'O'
java.text.SimpleDateFormat.compile(SimpleDateFormat.java:845)
java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:659)
阅读第一行本身。
SimplDateFormat 接受以下模式的一些示例。
new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z");
new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
new SimpleDateFormat("yyyy/MM/dd");
参考 - https://examples.javacodegeeks.com/core-java/text/java-dateformat-example/
您没有提供正确的日期格式。例如,您可以这样做:
new SimpleDateFormat("dd-MMM-yy")
但不是
new SimpleDateFormat("DD-MON-YY");
此错误是由于 Oracle 日期和时间格式说明符未被 SimpleDateFormat 完全支持。您应该更改此模式,或找到一种方法(实现一个函数)将其转换为 SimpleDateFormat 支持的模式。