SimpleDateFormat returns strange date with invalid date string

后端 未结 2 1409
我寻月下人不归
我寻月下人不归 2021-01-16 07:26

I try to parse time formating string ,now when I parse string \"2014-01-07 95:25:37\" , it return a date ,not throw ParseException . who know how to let it throw ParseExcept

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-16 08:04

    The cause of the problem is the time : 95:25:37 . Java tries to add this extra time to your days ,hence you are get additional 3 days.

    To prevent java from doing so, you can use the following :

     ft.setLenient(false);
    

提交回复
热议问题