Scala - How to set date format using SimpleDateFormat using json4s

I need a date format like

Tue May 31 17:46:55 +0800 2011

And the current formats I'm using

implicit val formats = Serialization.formats(NoTypeHints)

He will produce:

2011-05-31 17: 46: 55.0

How can I create formats that create a type string "Tue May 31 17:46:55 +0800 2011"?

+4
source share
1 answer
private def formatsWithDate(customDateFormat : SimpleDateFormat): Formats = {
    new DefaultFormats {
      override val dateFormatter = customDateFormat
    }
  }

This way you can set your own date format

Note: for version above 3.2.9, json4s will use the UTC time zone, regardless of which time zone you set in the date format

+3
source

All Articles