Why does parsing ’23:00 PM’ with SimpleDateFormat("hh:mm aa") return 11 a.m.?
Why does parsing ’23:00 PM’ with SimpleDateFormat(hh:mm aa) return 11 a.m.?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should be getting an exception, since “23:00 PM” is not a valid string, but Java’s date/time facility is lenient by default, when handling date parsing.
The logic is that 23:00 PM is 12 hours after 11:00 PM, which is 11:00 AM the following day. You’ll also see things like “April 31” being parsed as “May 1” (one day after April 30).
If you don’t want this behavior, set the lenient property to false on your SimpleDateFormat using DateFormat#setLenient(boolean), and you’ll get an exception when passing in invalid date/times.