I had asked this question already:
How do I get the current time in Elm?
And answered it by writing my own (now deprecated) variant of start-ap
You could create a Native module, and then expose a timestamp function that gets the time from Date.now() in JavaScript.
This is roughly what it would look like:
module Timestamp exposing (timestamp)
import Native.Timestamp
timestamp : () -> Int
timestamp a = Native.Timestamp.timestamp a
var _YourRepoUserName$your_repo$Native_Timestamp = function() {
return { timestamp: function(a) {return Date.now()}
}
port module Main exposing (..)
import Timestamp exposing (timestamp)
then you can use (timestamp ()) anywhere in Elm to get the current timestamp as an Int.
Note: I used timestamp : () -> Int because I couldn't get it to work otherwise. timestamp : Int simply returned the hardcoded time of first load.
Let me know if this could be improved.