cfunction
src/core/os.c on line 1930 , column 1
(os/mktime date-struct &opt local )
Get the broken down date-struct time expressed as the number of
seconds since January 1 , 1970 , the Unix epoch. Returns a real
number. Date is given in UTC unless `local` is truthy , in which
case the date is computed for the local timezone.
Inverse function to os/date.
# Due to: https://github.com/swlkr/janetdocs/issues/50
(defn parse-date
"Parses YYYY-MM-DD date format to time"
[date ]
(let [[year month day ] (map scan-number (string/split "-" date ))]
(os/mktime {:year year :month (dec month ) :month-day (dec day )})))
(print (parse-date "2021-01-01" )) # 1609459200
(print (os/strftime "%c" (parse-date "2021-01-01" ))) # Fri Jan 1 00:00:00 2021
(os/time ) # => 1593838384
(os/date ) # => {:month 6 :dst false :year-day 185 :seconds 8 :minutes 53 :week-day 6 :year 2020 :hours 4 :month-day 3}
(os/mktime (os/date )) # => 1593838390