【问题标题】:How to properly set a timezone in a clojure REPL?如何在 clojure REPL 中正确设置时区?
【发布时间】:2020-10-17 17:46:18
【问题描述】:

在 clojure REPL 上对 postgres 数据库运行查询时,时间戳字段以 UTC 显示,我需要它们位于 America/Sao_Paulo (UTC-3) 时区

到目前为止,我在 Intellij 的 REPL 上尝试了以下方法:

  • 在文件idea.vmoptions(intellij's)中设置-Duser.timezone=America/Sao_Paulo
  • :jvm-opts ["-Duser.timezone=America/Sao_Paulo"]添加到project.clj
  • 在 Intellij 的 REPL 配置中添加 -Duser.timezone=America/Sao_Paulo
  • 导出JAVA_OPTS="-Duser.timezone=America/Sao_Paulo:$JAVA_OPTS" 内部~/.zshrc

以及 Leiningen REPL 上的以下内容:

  • :jvm-opts ["-Duser.timezone=America/Sao_Paulo"]添加到project.clj
  • 导出JAVA_OPTS="-Duser.timezone=America/Sao_Paulo:$JAVA_OPTS" 内部~/.zshrc

到目前为止没有任何工作!

示例代码

(ns experiments
  (:require [next.jdbc :as jdbc]))

(def db
  {:dbtype   "postgres"
   :dbname   "<dbname>"
   :host     "<host>"
   :port     5432
   :user     "<user>"
   :password "<pass>"})

(def ds (jdbc/get-datasource db))

(jdbc/execute! ds ["select current_timestamp"])

【问题讨论】:

    标签: clojure timezone read-eval-print-loop leiningen


    【解决方案1】:

    您没有提到任何 Postgres 选项。请仔细研究this page 以获取信息和选项。

    如果上述方法不能解决您的问题,使用java.time 进行转换可能是最简单的方法。我还有一些帮助/便利功能available hereUnit tests 展示它们的实际操作,the source code 提供了来自 clojure 的 java.time 互操作示例。

    我会避免使用旧的 Joda Time 库,因为它们已经过时(被 java.time 取代)。我认为 Java 互操作是访问java.time 的最简单、最直接的方式。

    【讨论】:

      猜你喜欢
      • 2012-01-16
      • 2014-04-02
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 2023-04-03
      • 2014-05-11
      • 2019-05-28
      • 2020-10-17
      相关资源
      最近更新 更多