Skip to content

Instantly share code, notes, and snippets.

@aarkerio
Created January 22, 2020 22:31
Show Gist options
  • Save aarkerio/61d7a34e869b1c0628be2c753d2ee72e to your computer and use it in GitHub Desktop.
Save aarkerio/61d7a34e869b1c0628be2c753d2ee72e to your computer and use it in GitHub Desktop.
Clojure. Format an Instant
(:require [java-time :as jt]))
(defn format-date
"Format a Java instant"
[date]
(let [formatter (jt/format "dd-MM-yyyy HH:mm")]
(jt/format formatter (.atZone date (jt/zone-id)))))
;; clj-time is now deprecated
@deobald
Copy link

deobald commented Feb 9, 2021

I think line 6 should be a call to jt/formatter, not jt/format. I also don't understand the declarative (and as far as I can tell, incorrect) statement that "clj-time is now deprecated". I don't think anyone considers it a community standard lib.

Copy link

ghost commented Apr 27, 2021

user> (java-time/format "dd-MM-yyyy HH:mm" (java-time/zoned-date-time #inst "2021-04-20T06:53:03.108042000-00:00" (java-time/zone-id)))
"20-04-2021 06:53"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment