Skip to content
jsr-310 (java.time) api in Clojurescript
Clojure Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

A Clojurescript library that provides the jsr-310 (java.time) api.

Note: this is not a wrapper library, meaning there are not additional Clojurescript functions, only what java.time provides.

Underneath this lib is a pure JS implementation of java.time. This extends that by adding Clojurescript's equivalence, hash and comparison protocols to the java.time domain objects, providing externs and having the packages of java.time be mirrored by namespaces.

Related Libraries offers a one for one mapping of the classes and methods from java.time into a Clojure(Script) library

Using that library is tick, an intuitive Clojure(Script) library for dealing with time, intended as a replacement for clj-time.

time-literals is a Clojure(Script) library which provides tagged literals for objects from jsr-310 domain and depends on this library

my talk at Clojure/North 2019 provides some background


get it from Clojars

(require '[java.time :refer [LocalDate]])

(.parse LocalDate "2020-01-01")

Cross Platform (.cljc) Example

(ns foo
    #?(:cljs [java.time :refer [LocalDate]])
    [ :as t.i])
   #?(:clj (:import [java.time LocalDate])))
  (. LocalDate parse "2020-12-01")
  ;=> #time/date"2020-12-01"
    (. LocalDate parse "2020-12-01")
    (. LocalDate parse "2020-12-01"))
  ; => true  
  ; call a getter method
  (let [l (. LocalDate parse "2020-12-01")]
    (t.i/getter dayOfMonth l))

Getter Methods

Unfortunately, all java.time getter methods have had the 'get' part of their name removed in the underlying js lib. So instead of 'getNano' method, you have 'nano'. As a workaround, to write cross platform code that calls any getter methods on java.time objects, use the macro

NPM Dependency

The npm library that provides the jsr-310 api is provided via a foreign-lib. Whilst this is handy if you don't already have an npm build step, if you do want to depend directly on the js-joda npm lib you can do so. For more info see the tick docs on setup for use with ClojureScript


Copyright © 2019 Widd Industries

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

You can’t perform that action at this time.