【发布时间】:2017-06-04 14:37:37
【问题描述】:
我得到以下代码:
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
String now = new ObjectMapper().writeValueAsString(new SomeClass(LocalDateTime.now()));
System.out.println(now);
我明白了:
{"time":{"hour":20,"minute":49,"second":42,"nano":99000000,"dayOfYear":19,"dayOfWeek":"THURSDAY","month" :"JANUARY","dayOfMonth":19,"year":2017,"monthValue":1,"chronology":{"id":"ISO","calendarType":"iso8601"}}}
我想要实现的是ISO8601中的字符串
2017-01-19T18:36:51Z
【问题讨论】:
-
会不会有这样的工作:DateFormat df = new SimpleDateFormat("MM/dd/yy hh:mm a");然后:mapper.setDateFormat(df);