Question

I need a date format like

Tue May 31 17:46:55 +0800 2011

And the current formats I am using is

implicit val formats = Serialization.formats(NoTypeHints)

It will produce :

2011-05-31 17:46:55.0

How can I make the formats that produce string like "Tue May 31 17:46:55 +0800 2011" ?

Was it helpful?

Solution

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

By this way you can set your own date format

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top