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

时间:2013-10-12 04:34:14

标签: 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"等字符串的格式?

1 个答案:

答案 0 :(得分:3)

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

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

  

警告:对于3.2.9之前的版本,json4s将使用UTC时区,无论您在dateformat中设置了什么时区