我从我的API获取此日期字符串:ToList
但是这个日期是UTC格式的,我想在当地时间转换它,我该怎么办?
我试过了:
"2015-12-07T14:11:15.596Z"
但是它给我发了这个错误:
try
{
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return simpleDateFormat.parse(this.created_at);
}
catch (ParseException e)
{
Log.e("Error Date at Whisp", e.getMessage());
return null;
}
答案 0 :(得分:2)
您的日期格式模式错误。改为:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
有关更多信息,请参阅SimpleDateFormat
的javadoc答案 1 :(得分:1)
T
和Z
不在您的面具中
无论
created_at = created_at.replace ("T", "").replace ("Z", "");
或修改你的面具