使用clj时间按区域设置确定日期格式



我已经在谷歌上搜索了很长一段时间,但我找不到clj时间的最终解决方案。我想根据区域设置自动设置日期的格式,如本例或此处所示。使用clj时间,我将如何做到这一点?

谢谢&干杯

使用with-locale(http://clj-time.github.io/clj-time/doc/clj-time.format.html#var-带区域设置)

(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时间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"

相关内容

  • 没有找到相关文章

最新更新