将对象转化为json格式的时候,日期类型数据的处理

String s = JSONObject.toJSONString(student)

如果student中有某个属性是Date 日期格式 的,在经过上述转换以后,日期会变成一长串数字,此时需要对日期进行格式化

String s = JSONObject.toJSONString(student, SerializerFeature.WriteDateUseDateFormat)

SerializerFeature.WriteDateUseDateFormat  的默认格式是  yyyy-MM-dd HH:mm:ss

此时字符串中的日期格式就已经变成了格式化后的格式

 

posted @ 2024-01-15 15:01  星空物语之韵  阅读(95)  评论(0编辑  收藏  举报