philipbohun.com

Glojure by Example: Time Formatting and Parsing

Go layouts are not strftime patterns. They are a rendering of the reference instant Mon Jan 2 15:04:05 MST 2006. You write the layout by formatting that instant the way you want the output to look.

(let [[tm err] (time.Parse "2006-01-02 15:04" "2024-03-05 16:30")]
  (println (nil? err))
  (println (.Format tm "Mon Jan 02 2006"))
  (println (.Format tm "15:04"))
  (println (.Format tm time.RFC3339)))

time.RFC3339 is a layout constant, not a format string you assemble.

$ glj time-formatting.glj
true
Tue Mar 05 2024
16:30
2024-03-05T16:30:00Z

Next example: Random Numbers.