Maison  >  Questions et réponses  >  le corps du texte

java - 转换json格式时间乱码问题

http://img.mukewang.com/58468...

private static String dateFormat;
private static SerializeConfig mapping = new SerializeConfig();
static {
    dateFormat = "yyyy-MM-dd HH:mm:ss";
    mapping.put(Date.class, new SimpleDateFormatSerializer(dateFormat));
}
String jsonString = JSONObject.toJSONString(deal,mapping,SerializerFeature.WriteDateUseDateFormat);

这个方法是把jsonString放入redis中,但有两个方法同时放一个redis中,这两个方法的deal实体类中的属性还不相同,其他代码都一样,不知道是不是这个问题,希望有大神给解释一下

伊谢尔伦伊谢尔伦2716 Il y a quelques jours664

répondre à tous(2)je répondrai

  • 黄舟

    黄舟2017-04-18 10:28:14

    Il semble que le thread de SimpleDateFormat ne soit pas sûr et que la concurrence multithread en sera la cause

    répondre
    0
  • 天蓬老师

    天蓬老师2017-04-18 10:28:14

    Ça ne semble pas nécessaire d'être si compliqué, c'est très simple avec fastjson

            Map<String, Object> map = new HashMap<>();
            map.put("createTime", new Date());
            map.put("name", "simeon");
            String jstr = JSON.toJSONStringWithDateFormat(map, "yyyy-MM-dd HH:mm:ss");

    répondre
    0
  • Annulerrépondre