关于时间戳格式标准化,封装成工具类,直接调用即可。
public class JsonUtils { public static String getJson(Object object){ return getJson(object,"yyyy-MM-dd HH:mm:ss"); } public static String getJson(Object obiect,String dateFormat){ ObjectMapper mapper = new ObjectMapper(); //让他不返回时间戳,关闭时间戳功能 mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false); //时间格式化 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); //mapper指定时间格式为simpleDateFormat mapper.setDateFormat(simpleDateFormat); try { return mapper.writeValueAsString(obiect); } catch (JsonProcessingException e) { e.printStackTrace(); } return null; } //封装一个工具类;调用时 //return JsonUtils.getJson(new Date()); }