java ISO8601,使用Jackson以毫秒表示json
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
objectMapper.setDateFormat(new ISO8601DateFormat());
很好,但是这忽略了毫秒,如何在不使用非线程安全的SimpleDateFormatter
的情况下在日期中获取它们
你可以在下面搜索框中键入要查询的问题!
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
objectMapper.setDateFormat(new ISO8601DateFormat());
很好,但是这忽略了毫秒,如何在不使用非线程安全的SimpleDateFormatter
的情况下在日期中获取它们
# 1 楼答案
ISO8601DateFormat.format
调用ISO8601Utils.format(date)
,后者反过来调用^{false
参数告诉jackson不要包含毫秒似乎无法配置此类或设置任何参数,但幸运的是,它可以扩展:
然后我们可以在对象映射器中使用这个新类:
我用
new Date()
做了一个测试,结果是2017-07-24T12:14:26.817Z
(毫秒)