gpt4 book ai didi

date - 使用 clj-time 按区域设置确定日期格式

转载 作者:行者123 更新时间:2023-12-03 02:02:25 25 4
gpt4 key购买 nike

我已经通过 Google 搜索这个问题很长一段时间了,但我找不到 clj-time 的最终解决方案。我想按区域设置自动格式化日期,例如 this examplehere 。我该如何使用 clj-time 来做到这一点?

感谢与干杯

最佳答案

使用with-locale ( http://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"

关于date - 使用 clj-time 按区域设置确定日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25728420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com