Created
March 8, 2017 00:46
-
-
Save hongwei1/7c2ea8cf6aaa9f0389660744e48eb146 to your computer and use it in GitHub Desktop.
time format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
successJsonResponse(Extraction.decompose(json)(formats = new Formats { | |
import java.text.{ParseException, SimpleDateFormat} | |
val dateFormat = new DateFormat { | |
def parse(s: String) = try { | |
Some(formatter.parse(s)) | |
} catch { | |
case e: ParseException => None | |
} | |
def format(d: Date) = formatter.format(d) | |
private def formatter = { | |
val f = dateFormatter | |
f.setTimeZone(new GregorianCalendar().getTimeZone) | |
f | |
} | |
} | |
protected def dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
val importJsonDateFormat = {
val f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
//setting the time zone is important!
f.setTimeZone(TimeZone.getTimeZone("UTC"))
f
}