【发布时间】:2016-05-10 18:26:26
【问题描述】:
我正在尝试将时间戳(例如:“1493287973015”)从 JSON 转换为 Date 类型。
到目前为止,我创建了这个自定义解码器:
stringToDate : Decoder String -> Decoder Date
stringToDate decoder =
customDecoder decoder Date.fromTime
但它不起作用,因为它返回的是结果,而不是日期:
Function `customDecoder` is expecting the 2nd argument to be:
Time.Time -> Result String a
But it is:
Time.Time -> Date.Date
有没有办法进行转换?
【问题讨论】:
-
...如果是UNIX时间戳,记得multiple that value by 1000...
标签: elm