【发布时间】:2013-11-21 08:05:14
【问题描述】:
我有字符串11/08/2013 08:48:10
我使用SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
在解析时会抛出异常:无法解析的日期
这有什么问题?
String result = han.ExecuteUrl("http://"+han.IP+":8015/api/Values/GetLastChange");
Log.d("Dal","result date time "+result); #result is 11/08/2013 08:48:10
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date convertedDate = new Date();
try
{
convertedDate = dateFormat.parse(result);
}
catch (ParseException e)
{
e.printStackTrace();
}
【问题讨论】:
-
完成。 han 变量仅用于从返回日期的 url 获取结果
-
对于新读者来说,考虑扔掉长期过时且臭名昭著的麻烦
SimpleDateFormat和朋友,并将ThreeTenABP添加到您的Android项目中,以便使用java.time,现代Java日期和时间API .使用起来感觉好多了。 -
我无法复制。您的代码在我的桌面 Java 上运行良好。我得到了
Fri Nov 08 08:48:10 CET 2013。