使用 clj-time 将 Clojure #inst 即时时间转换为 Joda 时间
Convert Clojure #inst instant in time to Joda time with clj-time
使用 clj-time 库将 #inst "2017-01-01T12:00:00"
等 Clojure 时间瞬间解析为 Joda 时间的正确方法是什么?
如果您有一个 java.util.Date
对象:
(type #inst "2017-01-01T12:00:00+02:00")
;;=> java.util.Date
clj-time
有一个 clj-time.coerce
命名空间和一个 from-date
函数,该函数将 java.util.Date
对象作为输入。示例:
(require '[clj-time.coerce :as c])
((juxt type str) (c/from-date #inst "2017-01-01T12:00:00"))
;;=> [org.joda.time.DateTime "2017-01-01T12:00:00.000Z"]
另外 clj-time 现在提供 data-reader 自动强制 EDN to/from joda datetimes 中的日期:clj-time EDN support
(clojure.edn/read-string {:readers clj-time.coerce/data-readers}
"#clj-time/date-time \"2019-07-10T06:00:00.000Z\"")
==>
#clj-time/date-time "2019-07-10T06:00:00.000Z"
使用 clj-time 库将 #inst "2017-01-01T12:00:00"
等 Clojure 时间瞬间解析为 Joda 时间的正确方法是什么?
如果您有一个 java.util.Date
对象:
(type #inst "2017-01-01T12:00:00+02:00")
;;=> java.util.Date
clj-time
有一个 clj-time.coerce
命名空间和一个 from-date
函数,该函数将 java.util.Date
对象作为输入。示例:
(require '[clj-time.coerce :as c])
((juxt type str) (c/from-date #inst "2017-01-01T12:00:00"))
;;=> [org.joda.time.DateTime "2017-01-01T12:00:00.000Z"]
另外 clj-time 现在提供 data-reader 自动强制 EDN to/from joda datetimes 中的日期:clj-time EDN support
(clojure.edn/read-string {:readers clj-time.coerce/data-readers}
"#clj-time/date-time \"2019-07-10T06:00:00.000Z\"")
==>
#clj-time/date-time "2019-07-10T06:00:00.000Z"