cfunction
src/core/os.c on line 1815 , column 1
(os/date &opt time local )
Returns the given time as a date struct , or the current time if
`time` is not given. Returns a struct with following key values.
Note that all numbers are 0-indexed. Date is given in UTC unless
`local` is truthy , in which case the date is formatted for the
local timezone.
:seconds number of seconds [0-61 ]
:minutes number of minutes [0-59 ]
:hours number of hours [0-23 ]
:month-day day of month [0-30 ]
:month month of year [0 , 11 ]
:year years since year 0 (e.g. 2019 )
:week-day day of the week [0-6 ]
:year-day day of the year [0-365 ]
:dst if Day Light Savings is in effect
(defn get-time-str []
(let [{:hours h :minutes m :seconds s } (os/date )]
(string h ":" m ":" s )))
(get-time-str ) => "23:18:16"
(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"
(os/date )
# => {:month 6 :dst false :year-day 185 :seconds 38 :minutes 44 :week-day 6 :year 2020 :hours 4 :month-day 3}
(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}