Skip to content

Instantly share code, notes, and snippets.

@jjhop
Created January 31, 2018 22:54
Show Gist options
  • Save jjhop/5d80a8a8314c4be5ffc96dc69c1fab14 to your computer and use it in GitHub Desktop.
Save jjhop/5d80a8a8314c4be5ffc96dc69c1fab14 to your computer and use it in GitHub Desktop.
(import '(java.util Date Calendar)
'(java.text SimpleDateFormat))
(defn yesterday-start-as-string []
"Returns the beginning of yesterday as a formatted string.
For example 2015-12-21 00:00:00 - hours, minutes and seconds are
always zeros."
(let [dt (.getTime (doto (Calendar/getInstance)
(.setTime (Date.))
(.set Calendar/HOUR_OF_DAY 0)
(.set Calendar/MINUTE 0)
(.set Calendar/SECOND 0)
(.set Calendar/MILLISECOND 0)
(.set Calendar/DAY_OF_MONTH -1)))
ft (SimpleDateFormat. "yyyy-MM-dd HH:mm:ss")]
(.format ft dt)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment