Определите формат даты по локали с помощью clj-time

Я долго искал это через Google, и я не смог найти окончательного решения с помощью clj-time. Я хочу автоматически форматировать дату в соответствии с локалью, как в этом примере или здесь. Как бы я сделал это, используя clj-time?

Спасибо и Приветствия

1 ответ

Решение

Использование with-locale ( http://clj-time.github.io/clj-time/doc/clj-time.format.html)

(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"
Другие вопросы по тегам