I need to get yesterday's date (not user-based, but relative to the server) in the format YYYY-MM-DD
.
What is the best way to achieve this in Clojure?
With Java 8 Time API:
(import (java.time LocalDate)
(java.time.format DateTimeFormatter))
(def formatter (DateTimeFormatter/ofPattern "yyyy-MM-dd"))
(def yesterday (.minusDays (LocalDate/now) 1))
(.format formatter yesterday)
;; => "2017-04-05"
Or with Java 8 Time API Clojure wrapper: clojure.java-time
(require '[java-time :as t])
(def yesterday (t/minus (t/local-date)
(t/days 1)))
(t/format "yyyy-MM-dd" yesterday)
;; => "2017-04-05"
clj-time
(t/minus (t/now) (t/days 1))
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