With the below code snippet I am getting exception in Java SE 1.7 environment.Can anybody help me figure out problem with this code.
DateFormat df = new SimpleDateFormat("hh:mm a");
Date date = df.parse("10:00 PM");
Exception Details :
Exception in thread "main" java.text.ParseException: Unparseable date: "10:00 PM"
at java.text.DateFormat.parse(DateFormat.java:357)
at com.premute.ModuleTest.main(ModuleTest.java:74)
You seem to have a default Locale
which cannot parse the English PM
. Use the overloaded SimpleDateFormat
constructor which accepts a Locale
and provide it with an appropriate instance.
DateFormat df = new SimpleDateFormat("hh:mm a", Locale.ENGLISH);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.