SimpleDateFormat parse(string str) doesn't throw an exception when str = 2011/12/12aaaaaaaaa?

前端 未结 7 1836
野的像风
野的像风 2020-11-27 08:06

Here is an example:

public MyDate() throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy/MM/d\");
    sdf.setLenient(false);
    St         


        
7条回答
  •  难免孤独
    2020-11-27 08:20

    You can use the ParsePosition class or the sdf.setLenient(false) function

    Docs: http://docs.oracle.com/javase/7/docs/api/java/text/ParsePosition.html http://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html#setLenient(boolean)

提交回复
热议问题