Clojure的日期和時間處理庫:clj-time

jopen 10年前發布 | 26K 次閱讀 clj-time

clj-time是一個Clojure語言的日期和時間處理庫,封裝自 Joda Time 庫。

用法

clj-time.core

The main namespace for date-time operations in the clj-time library is clj-time.core.

=> (require '[clj-time.core :as t]) 

Create a DateTime instance with date-time, specifying the year, month, day, hour, minute, second, and millisecond:

=> (t/date-time 1986 10 14 4 3 27 456) #<DateTime 1986-10-14T04:03:27.456Z> 

Less-significant fields can be omitted:

=> (t/date-time 1986 10 14) #<DateTime 1986-10-14T00:00:00.000Z> 

Get the current time with now and the start of the Unix epoch withepoch.

Once you have a date-time, use accessors like hour and second to access the corresponding fields:

=> (t/hour (date-time 1986 10 14 22)) 22 

The date-time constructor always returns times in the UTC time zone. If you want a time with the specified fields in a different time zone, use from-time-zone:

=> (t/from-time-zone (t/date-time 1986 10 22) (t/time-zone-for-offset -2)) #<DateTime 1986-10-22T00:00:00.000-02:00> 

If on the other hand you want a given absolute instant in time in a different time zone, use to-time-zone:

=> (t/to-time-zone (t/date-time 1986 10 22) (t/time-zone-for-offset -2)) #<DateTime 1986-10-21T22:00:00.000-02:00> 

項目主頁:http://www.baiduhome.net/lib/view/home/1400571125550

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!