我越來越非法字符模式 'O'
java.lang.IllegalArgumentException異常:非法字符模式 'O' java.text.SimpleDateFormat.compile(SimpleDateFormat.java:845)
執行此代碼時:
DateFormat format = new SimpleDateFormat("DD-MON-YY");
我該如何解決這個問題?
我越來越非法字符模式 'O'
java.lang.IllegalArgumentException異常:非法字符模式 'O' java.text.SimpleDateFormat.compile(SimpleDateFormat.java:845)
執行此代碼時:
DateFormat format = new SimpleDateFormat("DD-MON-YY");
我該如何解決這個問題?
你的日誌是自explainatory,
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");