3
A
回答
6
使用:erlang.universaltime
获取时间(外生使用此为Ecto.DateTime.utc/0
),使用:calendar
转换成公历秒,减去15 * 60,转换回一个Erlang时间的元组,并投退给Ecto.DateTime
:
iex(1)> utc = :erlang.universaltime |> :calendar.datetime_to_gregorian_seconds
63638236105
iex(2)> fifteen_minutes_ago = (utc - 15 * 60) |> :calendar.gregorian_seconds_to_datetime |> Ecto.DateTime.cast!
#Ecto.DateTime<2016-08-12 15:33:25>
编辑:管道可能看起来更好:
:erlang.universaltime
|> :calendar.datetime_to_gregorian_seconds
|> Kernel.-(15 * 60)
|> :calendar.gregorian_seconds_to_datetime
|> Ecto.DateTime.cast!
|> IO.inspect
与以前相同的输出。
相关问题
- 1. NSTimeInterval 15分钟之前
- 2. Android - TimePicker分钟到15
- 3. 查找15分钟以前的文件
- 4. SolrCloud 15-20分钟
- 5. lstat()块15分钟
- 6. Array设置时间之前15分钟找到一个
- 7. 间隔15分钟的Timepicker
- 8. 15分钟递增查询
- 9. jqplot力蜱每15分钟
- 10. jQuery的Timepicker - 每15分钟
- 11. 15分钟时间序列
- 12. sql查询分为15分钟
- 13. 删除在mysql中输入15分钟前的记录
- 14. 如何在每15分钟查找当前位置
- 15. 使列在SQL如果分钟数高于15分钟
- 16. 3 cronjobs,15个分钟的间隔,相隔5分钟
- 17. 使用timedelta在python中添加15分钟到当前时间戳
- 18. 以15分钟递增的MySQL数据
- 19. AVPlayer实况广播15分钟左右
- 20. 如何让时间少于15分钟
- 21. 在R中15分钟时间聚合
- 22. 循环内增加时间15分钟
- 23. 15分钟后关闭javascript窗口
- 24. 使用服务器缓存15分钟
- 25. 从JNDI获取连接> 15分钟!
- 26. 将qDateTimeEdit限制为15分钟
- 27. BigQuery查询花费> 15分钟
- 28. 无法15分钟添加至00:00
- 29. 每15分钟刷新Azure Redis缓存
- 30. 春季执行方法,每15分钟
有['ago'(https://hexdocs.pm/ecto/Ecto.Query.API.html#ago/2),虽然你不能直接调用它(它意味着要使用的'例如'where子句)。 – evuez