I need to log some events on a Clojure Client-Server scenario, but it seems to me that Clojure does not provide a date/time function. Can any one confirm this or I am missing something here?! If I am correct then I need to use java interop, right?
If all you need is to get the current time and date for your logger, then this function is OK:
(defn now [] (new java.util.Date))
Now that you mentioned this, it would be useful to have support for immutable Date objects.
Java 1.8 added the java.time package to the core JDK to clean up many of the frustrations with the state of date & time in Java. Since java.time is now a widely available part of core Java with a much improved API, I would encourage you to give it the first look when writing new date & time code.
Here's how you can retrieve the current date and time:
(java.time.LocalDateTime/now)
There is a Clojure-wrapper library for Joda-Time. Or you'll have to use java interop with the standard Java API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With