Skip to content

Instantly share code, notes, and snippets.

@saralilyb
Created February 4, 2018 23:27
Show Gist options
  • Save saralilyb/8c9ec879bb47b75647d6ef3a16472426 to your computer and use it in GitHub Desktop.
Save saralilyb/8c9ec879bb47b75647d6ef3a16472426 to your computer and use it in GitHub Desktop.
makes an iso8601 timestamp using JUST CLOJURE WITHOUT SEVEN THOUSAND LIBRARIES COME ON KIDS LEARN HOW TO USE WHAT YOU HAVE
(defn maketimestamp
"makes iso8601 timestamp manually
(works pre java 8)
from https://stackoverflow.com/questions/3914404/how-to-get-current-moment-in-iso-8601-format-with-date-hour-and-minute"
[]
(let [tz (java.util.TimeZone/getTimeZone "UTC")
df (new java.text.SimpleDateFormat "yyyy-MM-dd'T'HH:mm:ss'Z'")]
(.setTimeZone df tz)
(.format df (new java.util.Date))))
@saralilyb
Copy link
Author

saralilyb commented Feb 4, 2018

can also do

(:import
    (java.time ZonedDateTime)
    (java.time.format DateTimeFormatter))

(defn time8601
  "generate iso8601 timestamp

   requires java 8 & import statements above
   https://gist.github.com/minimal/b79f50fe6cdd2f6da9698c4a47599afe"
  []
  (.. (ZonedDateTime/now) (format DateTimeFormatter/ISO_INSTANT)))

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