scala -- 如何使用 json4s 使用 SimpleDateFormat 自定义日期格式

标签 scala json4s

我需要一个日期格式

Tue May 31 17:46:55 +0800 2011



我使用的当前格式是
implicit val formats = Serialization.formats(NoTypeHints)

它将产生:

2011-05-31 17:46:55.0



如何制作生成字符串的格式,如 "Tue May 31 17:46:55 +0800 2011" ?

最佳答案

private def formatsWithDate(customDateFormat : SimpleDateFormat): Formats = {
    new DefaultFormats {
      override val dateFormatter = customDateFormat
    }
  }

通过这种方式,您可以设置自己的日期格式

Caution: for version earlier than 3.2.9, json4s will use UTC timezone, regardless of what timezone you set in the dateformat

关于scala -- 如何使用 json4s 使用 SimpleDateFormat 自定义日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19330564/

相关文章:

scala - 使用 json4s 将 [String,Any] 映射到压缩 json 字符串

json - 使用 json4s 从 json 字符串中提取键

scala - scalaz-stream 中带有 chunk 和 zipWithIndex 的令人困惑的行为

json - 如何使用带有 UTF-8 字符的 json4s 序列化 JSON?

scala - 如何在Scala中操作JSON AST

scala - 如何解析 json 并根据其内容提取到不同的案例类

scala - 使用 json4s 将 [String,Any] 映射到压缩 json 字符串

斯卡拉 future : what is the main thread expected to do while futures are executing?

scala - SBT:可以从磁盘读取变量吗?

scala - 用于理解的 map/flatmap 函数是什么?