What is the right way to parse Clojure time instants like #inst "2017-01-01T12:00:00"
to Joda time using the clj-time library?
Asked
Active
Viewed 1,807 times
4

Petrus Theron
- 27,855
- 36
- 153
- 287
2 Answers
5
If you have a java.util.Date
object:
(type #inst "2017-01-01T12:00:00+02:00")
;;=> java.util.Date
clj-time
has a clj-time.coerce
namespace with a from-date
function that takes java.util.Date
objects as input. Example:
(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"]

Sam Estep
- 12,974
- 2
- 37
- 75
0
Also clj-time now provides a data-reader to automatically coerce dates in 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"

John Conti
- 11
- 4