-2

我从 web 服务获取日期时间,实际上是从 sqlserver 数据库中提取数据,问题是当我尝试将字符串转换为日期时出现解析异常:

这是我的代码:

String tschedule = json.getString("ScheduledFor");
String tduration = json.getString("Duration");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
SimpleDateFormat dateFormat1 = new SimpleDateFormat("HH:mm:ss");

Date schedule = new Date();
Date duration = new Date();

try
{
schedule = dateFormat.parse(tschedule); //exception here, tschedule="2013-04-12T11:25:26.703"  
duration = dateFormat1.parse(tduration);//or exception here, tduration="03:10:00"
}
catch(Exception ex)
{
Log.e("MEETINGS SERVICE", "Parse exception: " + ex.getMessage());
}

更新:Logcat 输出:04-18 18:54:48.690:E/MEETINGS SERVICE(8601):DateParse 异常:无法解析日期:2013-04-12T11:25:26.703

4

1 回答 1

1

你错过了小数秒(粗体部分):

DateParse 异常:无法解析的日期:2013-04-12T11:25:26 .703

确保更改您的模式以包括以下内容:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
于 2013-04-19T00:04:57.613 回答