小编Koo*_*odi的帖子

Elixir/Phoenix中2个DateTime小时数之间的差异

我的目标是找到从现在到一些提供的date_time之间的小时差异.我试着这样做:

pry(1)> dt1
#DateTime<2017-10-24 05:12:46.000000Z>

pry(2)> Ecto.DateTime.to_erl(dt1)
** (FunctionClauseError) no function clause matching in Ecto.DateTime.to_erl/1    

    The following arguments were given to Ecto.DateTime.to_erl/1:

        # 1
        #DateTime<2017-10-24 05:12:46.000000Z>

    Attempted function clauses (showing 1 out of 1):

        def to_erl(%Ecto.DateTime{year: year, month: month, day: day, hour: hour, min: min, sec: sec})

    (ecto) lib/ecto/date_time.ex:608: Ecto.DateTime.to_erl/1
    # ............
Run Code Online (Sandbox Code Playgroud)

如何解决?或者有更好的方法来实现我的目标吗?

请注意,我不使用timex,也不会使用它,也不会使用任何第三方库.只有内置于Elixir/Erlang/Phoenix的内置.

datetime elixir

5
推荐指数
2
解决办法
2052
查看次数

标签 统计

datetime ×1

elixir ×1