Home  >  Q&A  >  body text

java - The pros and cons of various methods for fastjson to handle date type conversion

ExpIssue exp = new ExpIssue();
    exp.setCreateTime(new Date());
    exp.setDealContent("liahodbfoasdhf");
第一种: String jstr = JSON.toJSONStringWithDateFormat(exp, "yyyy-MM-dd HH:mm:ss");
第二种: String ste =  JSON.toJSONString(exp, SerializerFeature.WriteDateUseDateFormat);
第三种:SerializeConfig mapping = new SerializeConfig();
       mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
       String json = JSONObject.toJSONString(issue,mapping,SerializerFeature.WriteDateUseDateFormat);
            
            

Please ask the experts for help, which one has better performance on the basis of accurate conversion under high concurrency

世界只因有你世界只因有你2687 days ago720

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-06-10 09:50:00

    It is best to use Unix timestamp when transmitting time (seconds or milliseconds, just agree on both sides).

    If you use yyyy-MM-dd HH:mm:ss, if the time zones of the two servers are different, there will probably be problems.

    reply
    0
  • Cancelreply