Clojure的日期和时间处理库:clj-time

jopen 10年前

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.open-open.com/lib/view/home/1400571125550