How do I get the current time in Elm?

后端 未结 8 1334
庸人自扰
庸人自扰 2020-12-03 01:15

I\'m running elm-repl to play around with the language.

I\'d like to see what the current time is. How would I do that? It doesn\'t appear to be possible with the c

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 02:04

    If you want the time as of program start you can do the following:

    Now.elm

    module Now where
    
    import Native.Now
    
    loadTime : Float
    loadTime = Native.Now.loadTime
    

    Native/Now.js

    Elm.Native.Now = {};
    
    Elm.Native.Now.make = function(localRuntime) {
    
      localRuntime.Native = localRuntime.Native || {};
    
    
      localRuntime.Native.Now = localRuntime.Native.Now || {};
    
      if (localRuntime.Native.Now.values) {
        return localRuntime.Native.Now.values;
      }
    
      var Result = Elm.Result.make(localRuntime);
    
      return localRuntime.Native.Now.values = {
        loadTime: (new window.Date).getTime()
      };
    
    };
    

    your code

    programStart = Now.loadTime
    

提交回复
热议问题