您好,我是Elm的全新人物,我在获取当前时间和将它转换为Elm中的日期方面遇到了一些困难。Convert Time.now to Date - Elm
我有一个消息类型 - 消息和一个函数添加一个新的消息到模型。我正在尝试存储消息发布的时间以及文本和用户标识。
不过,我不断收到此错误 -
The argument to function `fromTime` is causing a mismatch.
59| Date.fromTime (currentTime Time.now)
^^^^^^^^^^^^^^^^^^^^
Function `fromTime` is expecting the argument to be:
Time
But it is:
x -> Time -> Time
Hint: It looks like a function needs 2 more arguments.
下面是代码
type alias Message =
{ text : String,
date : Date,
userId : Int
}
currentTime : task -> x -> Time -> Time
currentTime _ _ time =
time
newMessage : String -> Int -> Message
newMessage message id =
{ text = message
, date = Date.fromTime (currentTime Time.now)
, userId = id
}
我实在想不通是怎么回事。任何帮助将非常感激。谢谢。
很好的解释!非常感谢。 –