Loading...
# due to 0 indexing, you will often want to add 1 to things:
(defn short-date [d]
(let [{:year y :month mon :month-day d} d]
(string y "-" ( 1 mon) "-" ( 1 d))))
# Makes os/date like 2025-12-25
(short-date (os//date))
# From: https://codeberg.org/veqq/deforester/src/branch/master/deforester.janet
(defn time-string
``Gives current time as ISO 8601 string: 2025-10-12T11:43:14 https://en.wikipedia.org/wiki/ISO_8601
This accounts for `os/date` 0-indexing month and days which are 1-indexed in ISO 8601.``
[]
(let [{:year y :month mon :month-day d :hours h :minutes min :seconds s} (os/date)]
(string y "-" ( 1 mon) "-" ( 1 d) "T" h ":" min ":" s)))
veqqqPlayground(defn get-time-str []
(let [{:hours h :minutes m :seconds s} (os/date)]
(string h ":" m ":" s)))
(get-time-str) => "23:18:16"
tupini07Playground(defn to-double-digit-string [digit]
(string/slice (string "0" digit) -3))
(defn get-date-time-string [time]
(let [date (os/date time)
year (get date :year)
month (to-double-digit-string (get date :month))
day (to-double-digit-string (get date :month-day))
hours (to-double-digit-string (get date :hours))
minutes (to-double-digit-string (get date :minutes))
seconds (to-double-digit-string (get date :seconds))]
(string year "-" month "-" day "__" hours ":" minutes ":" seconds)))
(defn get-current-date-time-string []
(get-date-time-string (os/time)))
### USAGE
(get-current-date-time-string)
# => "2020-09-23__17:20:00"
harryvederciPlayground(os/date)
# => {:month 6 :dst false :year-day 185 :seconds 38 :minutes 44 :week-day 6 :year 2020 :hours 4 :month-day 3}
cellularmitosisPlayground(def time (os/time)) # => 1593838001
(os/date t)
# => {:month 6 :dst false :year-day 185 :seconds 41 :minutes 46 :week-day 6 :year 2020 :hours 4 :month-day 3}
(os/date t false)
# => {:month 6 :dst false :year-day 185 :seconds 41 :minutes 46 :week-day 6 :year 2020 :hours 4 :month-day 3}
(os/date t true)
# => {:month 6 :dst true :year-day 184 :seconds 41 :minutes 46 :week-day 5 :year 2020 :hours 23 :month-day 2}
(os/date t :local)
# => {:month 6 :dst true :year-day 184 :seconds 41 :minutes 46 :week-day 5 :year 2020 :hours 23 :month-day 2}
cellularmitosisPlayground