[英]Facing issue in DateFormat parsing
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. 使用下面的代码片段,我在Java SE 1.7环境中遇到了异常。有人可以帮助我找出此代码的问题吗?
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
. 您似乎有一个无法解析English
PM
的默认Locale
。 Use the overloaded SimpleDateFormat
constructor which accepts a Locale
and provide it with an appropriate instance. 使用重载的
SimpleDateFormat
构造函数 ,该构造函数接受Locale
并为其提供适当的实例。
DateFormat df = new SimpleDateFormat("hh:mm a", Locale.ENGLISH);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.