SpringMVC中将时间戳转换成自定义格式输出
类中的方法:
1 public String json3() throws JsonProcessingException { 2 3 ObjectMapper mapper = new ObjectMapper(); 4 5 // 不使用时间戳格式 6 mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false); 7 8 // 自定义时间格式 9 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 10 11 mapper.setDateFormat(sdf); 12 13 Date date = new Date(); 14 15 return mapper.writeValueAsString(date); 16 }

浙公网安备 33010602011771号