Search code examples
clojureclojurescript

How to convert instant time to date in clojure


I have an instant time in clojure as "2016-08-03T18:45:00.000-00:00". I want to convert it to only date ("2016-08-03"). How do I do this.

My actual date is in the format "2016-08-03T18:45:00Z". I converted it to instant using (c/to-date (f/parse "2016-08-03T18:45:00Z")).How to get only date?

Thank you


Solution

  • If you want to get just the date part of the date and time string:

    (require '[clojure.string :as str])
    
    (def date-str "2016-08-03T18:45:00.000-00:00")
    (first (str/split date-str #"T"))
    ;; => "2016-08-03"