【问题标题】:Clojure parse timestamp to stringClojure 将时间戳解析为字符串
【发布时间】:2014-09-05 08:53:01
【问题描述】:

我正在尝试将 clojure 时间戳转换为特定格式。我正在使用 clj-time 库。 https://github.com/clj-time/clj-time。这是我正在做的事情:

(f/unparse :year-month-day  (t/date-time 2010 10 3))

这看起来很像文档示例,但我不明白为什么我的 ClassCastException 看起来像这样:

ClassCastException clojure.lang.Keyword cannot be cast to org.joda.time.format.DateTimeFormatter  clj-time.format/unparse (format.clj:185)

感谢您的帮助。

【问题讨论】:

    标签: clojure clj-time


    【解决方案1】:

    定义解析器:

     (def custom-formatter (fmt/formatter "yyyy-MM-dd"))
    

    然后使用它:

    (fmt/unparse custom-formatter (time/date-time 2010 10 3))
    

    【讨论】:

      猜你喜欢
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 2021-02-08
      • 1970-01-01
      • 2018-09-10
      相关资源
      最近更新 更多