public class JsonUtils{
public static String getJson(Object object){
return getJson(Object,"yyyy-MM-dd HH:mm:ss");
}
public static String getJson(Object object,String dateFormat){
ObjectMapper mapper=new ObjectMapper();
//关闭时间戳功能
mapper.configure(SerializationFeature,WRITE_DATES_AS_TIMESTAMPS,false);
//自定义时间格式对象
SimpleDateFormat sdf=new SimpleDateFormat(dateFormat);
//让mapper指定时间日期格式位simpledateformat
mapper.setDateFormat(sdf);
try{
return mapper.writeValueAsString(object);
}catch(JsonProcessingException e){
e.printStackTrace();
}
return null;
}
}
JSON后端生成时间工具类
最新推荐文章于 2022-03-28 14:50:56 发布