Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the Clojure time and date libraries? [closed]

Tags:

clojure

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?

like image 441
dan Avatar asked Feb 17 '11 04:02

dan


3 Answers

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"
like image 110
Matt Curtis Avatar answered Nov 12 '22 15:11

Matt Curtis


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)
like image 40
wegry Avatar answered Nov 12 '22 14:11

wegry


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.

like image 1
nha Avatar answered Nov 12 '22 16:11

nha