SimpleDateFormat returns strange date with invalid date string

后端 未结 2 1398
我寻月下人不归
我寻月下人不归 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 07:41

    Use setLenient to validate the input date String

    ft.setLenient(false);
    
    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题