【发布时间】:2014-04-08 12:46:58
【问题描述】:
我在 ISO“2013-09-20T00:00:00Z”中收到 API 的响应,女巫是 GMT+0,我需要将其转换为设备的当前时区。
【问题讨论】:
-
您在 android 中的新事物与您要转换的日期无关。使用 Google 查找解决方案。
我在 ISO“2013-09-20T00:00:00Z”中收到 API 的响应,女巫是 GMT+0,我需要将其转换为设备的当前时区。
【问题讨论】:
使用SimpleDateFormat 解析它。看起来格式是 yyyy-MM-dd'T'HH:mm:ssX
“X”表示使用 ISO 8601 时区。
【讨论】:
试试这个
String s = "2013-09-20T00:00:00Z";
Calendar c = javax.xml.bind.DatatypeConverter.parseDateTime(s);
c.setTimeZone(TimeZone.getDefault());
s = javax.xml.bind.DatatypeConverter.printDateTime(c);
System.out.println(s);
【讨论】:
使用 Joda-Time 更轻松。
String input = "2013-09-20T00:00:00Z";
DateTime dateTime = new DateTime( input, DateTimeZone.getDefault() );
【讨论】: