4

使用clj-time库将 Clojure 时间瞬间解析#inst "2017-01-01T12:00:00"为 Joda 时间的正确方法是什么?

4

2 回答 2

5

如果你有一个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"]
于 2017-06-12T12:37:01.230 回答
0

clj-time 现在还提供了一个数据阅读器,可以自动将 EDN 中的日期强制转换为 joda 日期时间/从 joda 日期时间:clj-time EDN 支持

(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"
于 2019-07-11T19:57:05.463 回答