解析字符串到目前为止 [英] Parsing a String to Date
本文介绍了解析字符串到目前为止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要解析的字符串:
Sun 11月10日10:00:00 CET 2013
Sun Nov 10 10:00:00 CET 2013
我的代码:
substrings = "Sun Nov 10 10:00:00 CET 2013"
SimpleDateFormat parserSDF = new SimpleDateFormat("EEE MMM d HH:mm:ss ZZZ yyyy");
Date date = parserSDF.parse(substrings);
编译错误输出:
java.text.ParseException:Unparseable date:Sun Nov 10 10:00:00 CET 2013
at java.text.DateFormat.parse(Unknown Source)
...
java.text.ParseException: Unparseable date: "Sun Nov 10 10:00:00 CET 2013" at java.text.DateFormat.parse(Unknown Source) ...
推荐答案
可能你错过了正确的Locale。试试这个,在你的例子中:
Probably you are missing the correct Locale. Try this, in your example:
SimpleDateFormat parserSDF = new SimpleDateFormat("EEE MMM d HH:mm:ss ZZZ yyyy", Locale.US);
这篇关于解析字符串到目前为止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文