如何在Ecto.DateTime中增加天数? [英] How can I add days to Ecto.DateTime?

查看:52
本文介绍了如何在Ecto.DateTime中增加天数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样创建的日期时间:

I have a date-time which I create like this:

Ecto.DateTime.from_erl({{2015, 3, 10}, {0, 0, 0}})

这是Phoenix应用程序.我想在没有任何其他第三方库的情况下增加几天.怎么样?

It's a Phoenix app. I want to add days to it with no any additional third-party library. How?

推荐答案

您可以使用erlang的 模块来操作日期而无需其他依赖项.

You can use erlang's :calendar module to manipulate dates without additional dependencies.

添加天数的标准方法是使用:calendar.date_to_gregorian_days/1进行加法并使用:calendar.gregorian_days_to_date/1转换回元组格式.

A standard way of adding days would be to use :calendar.date_to_gregorian_days/1 do the addition and convert back to the tuple format with :calendar.gregorian_days_to_date/1.

这篇关于如何在Ecto.DateTime中增加天数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆