我从 API 获取此日期字符串:"2015-12-07T14:11:15.596Z"
但是这个日期是UTC格式的,我想将其转换为本地时间,我该怎么做?
我尝试过这个:
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;
}
但它返回给我这个错误:
Unparseable date: "2015-12-07T13:21:17.996Z" (at offset 10)
最佳答案
您的日期格式模式错误。更改为:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
有关更多信息,请参阅 SimpleDateFormat 的 javadoc
关于java - Android 将 UTC 日期转换为本地时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34150865/