Search code examples
clojureclj-time

Clojure parse timestamp to string


I am trying to convert a clojure timestamp to a specific format. I am using the clj-time library. https://github.com/clj-time/clj-time. Here is what I am doing:

(f/unparse :year-month-day  (t/date-time 2010 10 3))

Which looks a lot like the documentation example, but I don't understand why I got a ClassCastException looking like that:

ClassCastException clojure.lang.Keyword cannot be cast to org.joda.time.format.DateTimeFormatter  clj-time.format/unparse (format.clj:185)

Thanks for your help.


Solution

  • define a parser :

     (def custom-formatter (fmt/formatter "yyyy-MM-dd"))
    

    then use it:

    (fmt/unparse custom-formatter (time/date-time 2010 10 3))