Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62674b3

Browse files
author
Ryan Neufeld
committed
Merge pull request clojure-cookbook#253 from stevenproctor/current-date-clj-time
Add example of using clj-time to description of the current-date recipe
2 parents aad4d16 + cb96bbe commit 62674b3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

primitive-data/dates/current-date/current-date.asciidoc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ representing the present time and date.
1515
(defn now []
1616
(java.util.Date.))
1717
18-
(now)
18+
(now)
1919
;; -> #inst "2013-04-06T14:33:45.740-00:00"
2020
2121
;; A few seconds later...
@@ -56,6 +56,29 @@ benchmarking is what you're after. Additionally, you shouldn't try to
5656
use +currentTimeMillis+ as some sort of unique value - UUIDs do
5757
a much better job of this.
5858

59+
If you decide you would rather use
60+
https://github.com/clj-time/clj-time[clj-time] to work with dates, it
61+
provides the a function +clj-time.core/now+ to get the current +DateTime+.
62+
63+
[source,clojure]
64+
----
65+
(require '[clj-time.core :as timec])
66+
67+
(timec/now)
68+
;; -> #<DateTime 2013-04-06T14:35:15.453Z>
69+
----
70+
71+
Use +clj-time.local/local-now+ to retrieve a +DateTime+ instance for
72+
the present scoped to your machine's local time zone.
73+
74+
[source,clojure]
75+
----
76+
(require '[clj-time.local :as timel])
77+
78+
(timel/local-now)
79+
;; -> #<DateTime 2013-04-06T09:35:20.141-05:00>
80+
----
81+
5982
===== See Also
6083

6184
* See <<sec_primitives_dates_reader_literal>> for more information on the

0 commit comments

Comments
 (0)