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.
See also:
java.text.SimpleDateFormatjavadocUpdate: 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.
Alternatively, you can also use
Sto represent them as milliseconds. It won’t affect the final result since it’s zero anyway.