alibaba / fastjson

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
https://github.com/alibaba/fastjson2/wiki/fastjson_1_upgrade_cn
Apache License 2.0
25.75k stars 6.5k forks source link

关于时间格式化的问题-2019-09-06与1991-09-06获取时区一个是CST时区,一个是CDT时区 #2383

Open yetoce opened 5 years ago

yetoce commented 5 years ago

image

当我使用1991-09-06来反序列化得到Date对象时,时间是CDT格式的,但是我用2019-09-06来反序列化,得到的时间就是CST格式的

Omega-Ariston commented 5 years ago

是否可以提供下测试用例的信息呢?

naspart commented 5 years ago

是否可以提供下测试用例的信息呢?

image image

@Data
private static class JsonRequest {
    @JSONField(name = "create_time", format = "yyyy-MM-dd")
    private Date createTime;
}

@RequestMapping(value = "/json/v1", method = RequestMethod.GET)
public ResponseEntity<Object> json() {
    String str = "{\"create_time\":\"1991-09-06\"}";

    JsonRequest request = JSON.parseObject(str, JsonRequest.class);

    return new ResponseEntity < > (RestResultUtil.success(), HttpStatus.OK);
}

以上这段代码测试,使用的fastjson 版本1.2.47,无其他任何fastjson配置

Omega-Ariston commented 5 years ago

使用以下代码,并未复现你的现象:

public class Issue2383 {

    public static void main(String[] args) {
        String str1 = "{\"create_time\":\"1991-09-06\"}";

        JsonRequest request1 = JSON.parseObject(str1, JsonRequest.class);
        System.out.println(request1.createTime);

        String str2 = "{\"create_time\":\"2019-09-06\"}";

        JsonRequest request2 = JSON.parseObject(str2, JsonRequest.class);
        System.out.println(request2.createTime);
    }

    public static class JsonRequest {
        @JSONField(name = "create_time", format = "yyyy-MM-dd")
        public Date createTime;
    }
}

输出结果: Fri Sep 06 00:00:00 CST 1991 Fri Sep 06 00:00:00 CST 2019