我接管了一个Clojure项目,遇到了如下错误:
No implementation of method: :to-date-time of protocol: #'clj-time.coerce/ICoerce found for class: java.time.LocalDateTime
我试图在这里赋值的地方:
{ :start-date (time/to-string start-date) }
我使用clj时间作为依赖项。
我感到困惑的是,特别是它说没有实现方法::协议的截止时间的部分,即使我使用时间/字符串
我需要添加该协议吗?
我们将更加感激你的帮助。
我解决了这个问题。MYSQL 8连接器返回Java LocalDateTime,clj time试图将此LocalDateTime转换为Java 8 中不存在的Joda Date时间
我不得不进口那些:
(:import [java.time LocalDateTime]
[java.time.format DateTimeFormatter])
创建格式化程序:
(def formatter (DateTimeFormatter/ofPattern "yyyy-MM-dd HH:mm:ss"))
然后转换为字符串:
(defn date-parser [{:keys [start-date expiry-date]}]
{:start-date (.toString (.format start-date formatter))
:expiry-date (.toString (.format expiry-date formatter))})
特别感谢Steffan Westcott和Alan Thompson