[alibaba/fastjson]关于带时区字符串转换为LocalDateTime的问题

2024-09-06 287 views
5

image public static void main(String[] args) {

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key","2021-03-31T16:06:50+0000");
    jsonObject.put("key1","2021-03-31T17:06:50+01:00");
    jsonObject.put("key2","2021-03-31T08:06:50-08:00");
    jsonObject.put("key3","2021-03-31T10:06:50-06:00");
    LocalDateTime localDateTime = jsonObject.getObject( "key", LocalDateTime.class);
    LocalDateTime localDateTime1 = jsonObject.getObject( "key1", LocalDateTime.class);
    LocalDateTime localDateTime2 = jsonObject.getObject( "key2", LocalDateTime.class);
    LocalDateTime localDateTime3 = jsonObject.getObject( "key3", LocalDateTime.class);

    System.out.println(localDateTime);
    System.out.println(localDateTime1);
    System.out.println(localDateTime2);
    System.out.println(localDateTime3);

}

正常带了时区字符串转换为本地时间北京时间。 这上面的所有转换后都应该是 2021-04-01 00:06:50 但是得到的结果却不是这样的。

回答

5

在最新版本的 fastjson 中转换正常 3753

2

同上,你更新一下版本就ok了。

1

ok 好的