java

时间戳

rzk · 4月12日 · 2020年本文共549个字 · 预计阅读2分钟84次已读
 1     @RequestMapping("/j3")
 2     public String JsonDome3() throws Jso睿共享nProcessingException {
 3         ObjectMapper mapper = new ObjectMapper();
 4         Date date = new Date();
 5         //自定义日期的格式
 6         SimpleDateFormat simpleDateFormat = new SimpleDateFormat睿共享("yyyy-MM-dd:HH:mm:ss");
 7         String s = simpleDateFormat.format(date);
 8         //ObjectMapper 时间解析后悔的默认格式为:Timestamp 睿共享 时间戳
 9         return  mapper.writeValueAsString(s);
10         //"2020-04-12:23:41:12"
11     }

时间戳

1     @RequestMapping("/j3")
2     public Strin睿共享g JsonDome3() throws JsonProcessingException {
3         ObjectMapper mapper = new ObjectMapper();
4 
5睿共享 
6         Date date = new Date();
7 
8         return  mapper.writeValueAsString(date);
9     }

0 条回应