从IPython控制台:
In [16]: b
Out[16]: datetime.datetime(2008, 3, 1, 0, 0)
In [17]: e
Out[17]: datetime.datetime(2010, 5, 2, 0, 0)
In [18]: rrule(MONTHLY).between(b, e, inc=True)
Out[18]:
[datetime.datetime(2009, 3, 6, 14, 42, 1),
datetime.datetime(2009, 4, 6, 14, 42, 1),
datetime.datetime(2009, 5, 6, 14, 42, 1),
datetime.datetime(2009, 6, 6, 14, 42, 1),
datetime.datetime(2009, 7, 6, 14, 42, 1),
datetime.datetime(2009, 8, 6, 14, 42, 1),
datetime.datetime(2009, 9, 6, 14, 42, 1),
datetime.datetime(2009, 10, 6, 14, 42, 1),
datetime.datetime(2009, 11, 6, 14, 42, 1),
datetime.datetime(2009, 12, 6, 14, 42, 1),
datetime.datetime(2010, 1, 6, 14, 42, 1),
datetime.datetime(2010, 2, 6, 14, 42, 1),
datetime.datetime(2010, 3, 6, 14, 42, 1),
datetime.datetime(2010, 4, 6, 14, 42, 1)]
如何从开始(between()
)日期开始b
返回日期?
答案 0 :(得分:12)
你需要将b
传递给rrule,就像这样:
rrule(MONTHLY, dtstart = b).between(b, e, inc=True)
从这些文档(http://labix.org/python-dateutil)看,调用rrule而不指定dtstart将使用datetime.datetime.now()作为您稍后应用between
的序列的起点。这就是为什么你的价值观始于2009-03-06。