Android将UTC日期转换为本地时区

我从我的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

TZ不在你的面具中

 created_at = created_at.replace ("T", "").replace ("Z", ""); 

或修改你的面具