3

我已经通过谷歌搜索了很长一段时间,但我找不到 clj-time 的最终解决方案。我想通过语言环境自动格式化日期,就像在这个例子这里。我将如何使用 clj-time 执行此操作?

感谢和干杯

4

1 回答 1

4

使用with-localehttp://clj-time.github.io/clj-time/doc/clj-time.format.html#var-with-locale

(require '[clj-time.core :as time] '[clj-time.format :as fmt])
(import '[java.util Locale])

(def custom-formatter (fmt/formatters :rfc822))
(def ja-formatter (fmt/with-locale custom-formatter (Locale. "ja")))
(fmt/unparse ja-formatter (time/date-time 2010 10 3))
> "日, 03 10 2010 00:00:00 +0000"

-更新-

joda-time DateTimeFormat 的使用示例:

(require '[clj-time.core :as time] '[clj-time.format :as fmt])
(import '[java.util Locale])
(import '[org.joda.time.format DateTimeFormat])
(def custom-formatter (DateTimeFormat/longDate))
(def ja-formatter (fmt/with-locale custom-formatter (Locale. "ja")))
(fmt/unparse ja-formatter (time/date-time 2010 10 3))
"2010/10/03"
(def us-formatter (fmt/with-locale custom-formatter (Locale. "us")))
(fmt/unparse us-formatter (time/date-time 2010 10 3))
"October 3, 2010"
于 2014-09-08T16:58:18.323 回答