字符串转化总结

313 阅读1分钟

使用FastJson把对象转String,Date时间变成时间戳问题:

将map集合转为json对象时遇到一个问题。map中的value为日期格式如"2019-03-01",在使用

JSONObject.toJSON(map).toString()

显示正常格式使用的内部函数应为:

JSONObject.toJSONStringWithDateFormat(suppliesSiteAlarmDTO, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat)

方法:

 public static String toJSONStringWithDateFormat(Object object, String dateFormat,
                                                          SerializerFeature... features) {
        return toJSONString(object, SerializeConfig.globalInstance, null, dateFormat, DEFAULT_GENERATE_FEATURE, features);
    }