philipbohun.com

Glojure by Example: Epoch

time.Unix builds a time from seconds and nanoseconds since 1970-01-01 UTC. Formatting that value in UTC prints the epoch. Formatting it without UTC uses the local zone.

(def epoch (.UTC (time.Unix 0 0)))
(println (.Format epoch time.RFC3339))
(println (.Unix epoch))

.Unix converts a parsed time back to seconds. This instant is midnight at the start of 5 March 2024, UTC.

(let [[tm err] (time.Parse time.RFC3339 "2024-03-05T00:00:00Z")]
  (println (nil? err))
  (println (.Unix tm)))

The epoch second is zero.

$ glj epoch.glj
1970-01-01T00:00:00Z
0
true
1709596800

Next example: Time Formatting and Parsing.