The following code causes an "Unparseable date" exception when executed. Is there any way I can tell SimpleDateFormat the date string must ends with 00?
public class Main {
public static void main(String[] args) {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss00");
try {
Date date = format.parse("2009030916301600");
} catch (ParseException ex) {
System.out.println("Exception" + ex);
}
}
}
Use singlequotes to represent literal text.
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss'00'");
java.text.SimpleDateFormat javadocUpdate: it didn't work here after a quick test. I suspect an uncovered corner case in javadoc. After all, you can just leave them away.
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
Alternatively, you can also use S to represent them as milliseconds. It won't affect the final result since it's zero anyway.
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssS");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With