在长生不老药中是否有类似 get DaysInMonth 的东西?

Is there something like get DaysInMonth for in elixir?

我在 Ecto.DateTime 上搜索过,但遗憾的是没有找到任何有用的信息。有没有办法得到这个月的最后一天?

我有一个查询,我从昨天(7 月 31 日)到今天(8 月 1 日)从 psql 加载订单,今天我只使用 1,但昨天它可以是 31, 30、29 或 28。有没有办法知道上个月有多少天?

提前致谢,感谢任何建议!

:calendar.last_day_of_the_month/2 接受年份和月份作为参数。

iex(1)> :calendar.last_day_of_the_month(2000, 2)
29
iex(2)> :calendar.last_day_of_the_month(2001, 2)
28

last_day_of_the_month(Year, Month) -> LastDay

Types:

Year = year()
Month = month()
LastDay = ldom()

Computes the number of days in a month.

您可以在 Elixir 的 Calendar.ISO 实现中使用 days_in_month/2 函数:

Calendar.ISO.days_in_month(year, month)

例如,Calendar.ISO.days_in_month(2019, 7) 将 return 31

您可以在此处的文档中找到更多信息:https://hexdocs.pm/elixir/Calendar.ISO.html#days_in_month/2