我从 2011 年开始使用我的备份脚本,完全没有问题。但是自 2013 年初以来,我遇到了正确的周数问题。
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.strftime("%W", time.localtime())
'02'
但我们有第 3 周
难道我做错了什么?它一直工作到2013年。
谢谢。
最佳答案
新年中第一个星期一之前的所有天都被视为第 0 周。 docs
看看日历:
import calendar
print calendar.month(2013,1)
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
在标准库中,您可以使用
datetime.isocalendar()
:from datetime import datetime
datetime.date(datetime.now()).isocalendar()[1]
关于python - 2013 年的周数错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14314343/