Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在python中如何找到过去6个月的总天数?
例如今天是7 November(本月 7 天),十月有 31 天,依此类推,直到最后 6 个月,现在我需要找到一个月中所有天数的总数(直到最后 6 个月)像
7 November
7(11 月) + 31(10 月) + 30(9 月) +... 直到从现在开始的最后 6 个月
与dateutil:
dateutil
>>> from dateutil.relativedelta import relativedelta >>> import datetime >>> delta = relativedelta(months=6) >>> six_month_away = datetime.date.today() - delta >>> abs((six_month_away - datetime.date.today()).days) 184