无法将日期字符串解析为日期 [英] Unable to parse date String to Date
问题描述
String mail_delivered =31.10.2013 17: 57:58 CET
try {
DateFormat df = new SimpleDateFormat(dd.MM.yyyy HH:mm:ss z,Locale.GERMAN);
日期结果= df.parse(mail_delivered);
System.out.println(result);
} catch(ParseException pe){
pe.printStackTrace();
}
错误消息是java.text.ParseException:不可稀释的日期:[31.10.2013 17:57:58 CET]
,我不知道发生了什么。
我请
提前感谢。
编辑:好的。我把它改成英文,但我仍然有同样的问题。我不想更改输入,因为它来自邮件数据库。任何其他想法?
String mail_delivered =31.10.2013 17:57:58 CET;
try {
DateFormat df = new SimpleDateFormat(dd.MM.yyyy HH:mm:ss z,Locale.ENGLISH);
日期结果= df.parse(mail_delivered);
System.out.println(result);
} catch(ParseException pe){
pe.printStackTrace();
}
我发现问题。我是盲目的来自数据库的Sting是 [31.10.2013 17:57:58 CET]
,而不是$ code> 31.10.2013 17:57:58 CET
谢谢。
中欧时代是MitteleuropäischeZeit,所以如果你想使用 Locale.GERMAN
,将 CET
更改为 MEZ
,它的工作原理。
String mail_delivered =31.10.2013 17 :57:58 MEZ;
有关给定区域设置的所有法定时区字符串的列表,请使用以下命令:
DateFormatSymbols.getInstance(Locale.GERMAN).getZoneStrings()
im want to parse a date String to a Date. I was looking in some other questions, but I didn't find an answer.
String mail_delivered = "31.10.2013 17:57:58 CET";
try {
DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss z", Locale.GERMAN);
Date result = df.parse(mail_delivered);
System.out.println(result);
} catch (ParseException pe) {
pe.printStackTrace();
}
The error message is java.text.ParseException: Unparseable date: "[31.10.2013 17:57:58 CET]"
and I don't know what's wrong.
Can you help me please. Thanks in advance.
Edit: ok. i canged it to english, but i'have still the same problem. I wouldn't like to change the input, because it comes from a mail database. Any other ideas?
String mail_delivered = "31.10.2013 17:57:58 CET";
try {
DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss z", Locale.ENGLISH);
Date result = df.parse(mail_delivered);
System.out.println(result);
} catch (ParseException pe) {
pe.printStackTrace();
}
I found the problem. I was blind. The Sting from the Database was [31.10.2013 17:57:58 CET]
, not 31.10.2013 17:57:58 CET
Thank you.
In German, "Central European Time" is "Mitteleuropäische Zeit", so if you want to use Locale.GERMAN
, change CET
to MEZ
and it works.
String mail_delivered = "31.10.2013 17:57:58 MEZ";
For a list of all the legal time zone strings for a given locale, use this:
DateFormatSymbols.getInstance(Locale.GERMAN).getZoneStrings()
这篇关于无法将日期字符串解析为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!