将字符串“11-10-10 12:00:00”转换为进入日期对象
可能的重复:
如何在java中解析日期?
我想转换字符串“11-10-10 12:00:00”
到 Date
对象中,但我无法这样做。你能帮我一下吗?
我有一个 Date 对象,其值为“Mon Oct 11 00:00:00 IST 2010”
DateFormat newDateFormat = new SimpleDateFormat("dd-MM-yy hh:mm:ss");
String strDate = newDateFormat.format(tempDate);
//**i got strDate as strDate is : 11-10-10 12:00:00**
DateFormat newDateFormat1 = new SimpleDateFormat("dd-MM-yy hh:mm:ss");
try {
tempDate = newDateFormat1.parse(strDate);
// **getting tempDate as - Mon Oct 11 00:00:00 IST 2010**
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Possible Duplicate:
how to parse date in java?
I want to convert the string "11-10-10 12:00:00"
into a Date
object, but I am not able to do so. Can you please help me out?
I have the Date object which has the value "Mon Oct 11 00:00:00 IST 2010"
DateFormat newDateFormat = new SimpleDateFormat("dd-MM-yy hh:mm:ss");
String strDate = newDateFormat.format(tempDate);
//**i got strDate as strDate is : 11-10-10 12:00:00**
DateFormat newDateFormat1 = new SimpleDateFormat("dd-MM-yy hh:mm:ss");
try {
tempDate = newDateFormat1.parse(strDate);
// **getting tempDate as - Mon Oct 11 00:00:00 IST 2010**
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是ideone 演示
Here is ideone demo
我认为这是 Java 代码——不是我的专长——但我认为您的问题是格式字符串中的“hh”,这导致
parse
解释为“12:00: 00”作为午夜而不是中午。尝试将其更改为“HH”,看看解析是否正确。I think this is Java code—not my specialty—but I think your issue is the "hh" in your format string, which causes
parse
to interpret "12:00:00" as midnight instead of noon. Try changing it to "HH" and see if that parses correctly.您需要使用印地语的 CultureInfo,它是“hi-IN”。有关文化的完整列表,请查看此链接 CultureInfo
You need to use CultureInfo for Hindi it is "hi-IN". For full list of cultures check this link CultureInfo