How do I get a Unix Timestamp in Clojure?

Brad Koch picture Brad Koch · Jul 2, 2013 · Viewed 19.7k times · Source

I want to know what the current timestamp is. The best I can do thus far is define my own function that does this:

(int (/ (.getTime (java.util.Date.)) 1000))

Is there a standard function for fetching the Unix timestamp with clojure?

Answer

Alex picture Alex · Jul 2, 2013

Pretty much all JVM-based timestamp mechanisms measure time as milliseconds since the epoch - so no, nothing standard** that will give seconds since epoch.

Your function can be slightly simplified as:

(quot (System/currentTimeMillis) 1000)

** Joda might have something like this, but pulling in a third-party library for this seems like overkill.