การแปลงเวลายุคเป็นวันที่มนุษย์สามารถอ่านได้ใน Clojure

ฉันมีเวลายุค Unix ฉันจะแปลงเป็นสตริงวันที่ที่มนุษย์อ่านได้อย่างไร ฉันได้ตรวจสอบ clj-time แล้ว (https://github.com/clj-time/clj-time) แต่ดูเหมือนว่าจะเปลี่ยนจากยุคที่อ่านได้ไปจนถึงยุคเท่านั้น ขอบคุณ.


person Zuriar    schedule 29.02.2016    source แหล่งที่มา


คำตอบ (2)


คุณยังสามารถใช้การโทรพื้นเมืองได้:

(str (java.util.Date. (System/currentTimeMillis)))
;; => "Mon Feb 29 21:59:51 MSK 2016"
person trancaruas    schedule 29.02.2016
comment
หรือบางทีอาจจะดีกว่าในปัจจุบัน (java.time.Instant/ofEpochMilli (Long/parseLong "1456774240403")) - person glts; 29.02.2016

คุณสามารถบังคับให้เป็นวันที่และเวลา จากนั้นใช้ตัวจัดรูปแบบ (ในตัวหรือสร้างเอง)

(require '[clj-time.format :as f])
(require '[clj-time.coerce :as c])

(f/unparse  (f/formatters :date-time) (c/from-long 1000000000000))

โปรดทราบว่า c/from-long ใช้เวลาเป็นมิลลิวินาที

person z7sg Ѫ    schedule 29.02.2016