from time import strftime, localtime, time
from calendar import monthrange
def uberdate(n):
if n == 0: return strftime('%Y, %m').split(', ')
month = int(strftime('%m'))
aDay = 60*60*24
offset = aDay # One day to start off with
for i in range(0, n):
while int(strftime('%m', localtime(time()-offset))) == month:
offset = offset+aDay
month = int(strftime('%m', localtime(time()-offset)))
return strftime('%Y, %m', localtime(time()-offset)).split(', ')
print(uberdate(5))
这将产生:
我不知道为什么我会投反对票,但引用OP的话:
这就是我的函数所产生的…
反馈给其他人,在随机投票前给予反馈。你知道吗
您可以使用
python-dateutil
模块来实现这一点。https://pypi.python.org/pypi/python-dateutil相关问题 更多 >
编程相关推荐