如何获取 Elm 的当前时间? [英] How do I get the current time in Elm?

查看:33
本文介绍了如何获取 Elm 的当前时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 elm-repl 来尝试使用该语言.

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 current library. Why is that?

我制作了一个包来帮助解决这个问题.http://package.elm-lang.org/packages/z5h/time-应用

I made a package to help with this. http://package.elm-lang.org/packages/z5h/time-app

这是在 elm 0.15 周围被问到的 - 在 elm 0.17 和 0.17 中情况有所不同0.18:见我该怎么做获取 Elm 0.17/0.18 中的当前时间?

This was asked around elm 0.15 - things are different in elm 0.17 & 0.18: see How do I get the current time in Elm 0.17/0.18?

推荐答案

为了解决我自己的问题,我创建了 StartApp 的一个变体,其中包含每个操作的时间戳.
所以更新函数有签名:
<代码>更新:动作->时间 ->模型 ->(模型,效果动作)

To resolve my own question, I've created a variant of StartApp that includes a timestamp on each action.
So the update function has signature:
update : action -> Time -> model -> (model, Effects action)

要点在这里.https://gist.github.com/z5h/41ca436679591b6c3e51

这篇关于如何获取 Elm 的当前时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆