In case you have json with an ISO date string like this
JSON.stringify({date: new Date()})
// -> "{"date":"2016-12-12T13:24:34.470Z"}"
You can map it to elm Date
type:
import Html exposing (text)
import Json.Decode as JD
import Date
payload = """{"date":"2016-12-12T13:24:34.470Z"}"""
dateDecoder : JD.Decoder Date.Date
dateDecoder =
JD.string
|> JD.andThen ( \str ->
case Date.fromString str of
Err err -> JD.fail err
Ok date -> JD.succeed date )
payloadDecoder : JD.Decoder Date.Date
payloadDecoder =
JD.field "date" dateDecoder
main =
JD.decodeString payloadDecoder payload
|> toString
|> text