如何与 Ecto 一起获得明天的约会时间?



我可以像这样使用 Ecto 获取当前日期时间:

Ecto.DateTime.utc

但是我如何获得明天的约会

Ecto.DateTime.utc + timedelta 1 day

Timex.shift(Timex.now, days: 1)

https://github.com/bitwalker/timex

这个答案怎么样?

Ecto.DateTime.utc 
|> Ecto.DateTime.to_erl 
|> :calendar.datetime_to_gregorian_seconds 
|> Kernel.+(86400) 
|> :calendar.gregorian_seconds_to_datetime 
|> Ecto.DateTime.from_erl
iex(3)> t = DateTime.utc_now()
#DateTime<2018-07-17 08:22:11.472192Z>
iex(4)> n = %{t | day: t.day + 1}
#DateTime<2018-07-18 08:22:11.472192Z>
iex(5)> n
#DateTime<2018-07-18 08:22:11.472192Z>
iex(6)> m = %{t | day: t.day - 1}
#DateTime<2018-07-16 08:22:11.472192Z>
iex(7)> m
#DateTime<2018-07-16 08:22:11.472192Z>

最新更新