简体   繁体   English

将 GMT+0 给出的日期转换为当前时区

[英]Convert date given from GMT+0 to current time zone

我在 ISO "2013-09-20T00:00:00Z" 中收到 API 的响应是 GMT+0,我需要将其转换为设备的当前时区。

Use a SimpleDateFormat to parse it.使用SimpleDateFormat来解析它。 It looks like the format would be yyyy-MM-dd'T'HH:mm:ssX看起来格式是 yyyy-MM-dd'T'HH:mm:ssX

The 'X' indicates use of the ISO 8601 time zone. “X”表示使用 ISO 8601 时区。

try this尝试这个

    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);

Easier with Joda-Time.使用 Joda-Time 更容易。

String input = "2013-09-20T00:00:00Z";
DateTime dateTime = new DateTime( input, DateTimeZone.getDefault() );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM