我有一个这种格式的日期{Y,M,D}
。是否有任何好的支持库或者,我可以使用简单的技巧,比如从这个日期减去三个月,而不会遇到无效日期、闰年等问题。
我最新的类似用途是在 MySql 中,您可以在其中键入:
Select '2011-05-31' - Interval 3 Month;
产生'2011-02-28'
。我对如何自己编写这个库不感兴趣,这是我想避免的。
我有一个这种格式的日期{Y,M,D}
。是否有任何好的支持库或者,我可以使用简单的技巧,比如从这个日期减去三个月,而不会遇到无效日期、闰年等问题。
我最新的类似用途是在 MySql 中,您可以在其中键入:
Select '2011-05-31' - Interval 3 Month;
产生'2011-02-28'
。我对如何自己编写这个库不感兴趣,这是我想避免的。
1> calendar:gregorian_days_to_date(calendar:date_to_gregorian_days({2011, 7, 14}) - 90).
{2011,4,15}
Use edate - specifically the shift function.
> edate:shift({2011,5,31}, -3, months).
{2011,2,28}
Under the hood it uses the calendar module, so it correctly deals with all of the corner cases.
我为这类事情创建了一个 GitHub gist,其中包含一些有用的实用程序。如果你愿意,可以随意偷走它。