I couldn't find libraries dealing with Time and Date in http://clojure.org/libraries. Are there any, or is this something I have to figure out how to do directly with Java?
clj-time is a wrapper around Java Joda-Time.
If you use Leiningen or Maven, you can add it to your project via Clojars.
There are lots of samples on the GitHub page which show how to do date arithmetic and parsing/formatting. For example:
(in-minutes (duration (date-time 1986 10 2) (date-time 1986 10 14)))
;; gives 17280
(def custom-formatter (formatter \"yyyyMMdd\"))
(parse custom-formatter "20100311")
;; gives #<DateTime 2010-03-11T00:00:00.000Z>
(unparse custom-formatter (date-time 2010 10 3))
;; gives "20101003"
This is an old question, but the new LocalDate class in Java 8 is a no libraries required way to accomplish this.
(ns example
(:import (java.time LocalDate format.DateTimeFormatter)))
(def formatting (DateTimeFormatter/ofPattern
"MM/dd/yyyy"))
(LocalDate/parse "08/06/2015" formatting)
I have used clj-time
, which wraps Joda Time without any problems in the past.
There is also dm3/clojure.java-time
, which wraps the Java 8 Date-Time API.
There is also a related namespace since Clojure 1.8 : clojure.instant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With