我有一个原始的sql查询,它返回一个datetime字段,我想返回一个带有这些结果的json。Elixir将datetime转换为字符串
如果我把返回值,我收到了抱怨:
(Poison.EncodeError) unable to encode value: {{2017, 3, 21}, {0, 0, 0, 0}}
如果我尝试使用Timex
将其转换为字符串:
Timex.format!(Ecto.DateTime.from_erl(datetime_field), "%Y-%m-%d %H:%M:%S", :strftime)
我得到:
** (FunctionClauseError) no function clause matching in Ecto.DateTime.from_erl/1
如果我跳过from_erl
部分:
Timex.format!(datetime_field, "%Y-%m-%d %H:%M:%S", :strftime)
我得到:
** (Poison.EncodeError) unable to encode value: {:error, :invalid_date}
wa不会很快找到这个 –