philipbohun.com

Glojure by Example: Time

time.Parse builds a time from a layout and a string, and returns the time plus an error. Format prints one. Layouts use Go's reference time, shown on the formatting page. Weekday and Year are methods.

(let [[tm err] (time.Parse time.RFC3339 "2024-03-05T15:04:05Z")]
  (println (nil? err))
  (println (.Format (.UTC tm) "2006-01-02 15:04:05"))
  (println (str (.Weekday tm)))
  (println (.Year tm)))

time.Now is the current time. Comparing its Unix second to zero shows that the clock is readable without baking today's date into the output.

(println (pos? (.Unix (time.Now))))

The parsed instant is in March 2024.

$ glj time.glj
true
2024-03-05 15:04:05
Tuesday
2024
true

Next example: Epoch.