As the title reads, how can I convert a UNIX timestamp, e.g. 1458297862, into a Date object in Elm?
Date.fromString
does not seem to accept it, and Date.fromTime
gives the wrong answer.
You can use Date.fromTime
, but you have to multiply that value by 1000
.
This gives you the date you'd expect:
Date.fromTime 1458297862000
I came across this answer and it didn't quite work in 0.18.
I found that Date.fromTime wouldn't accept arbitrary integers. The reason is that it's expecting floats, so you'd really want:
Date.fromTime (toFloat 1458297862000)