Python time.strftime("%W") 怎么是第五周,今天不是第七周吗?

2021-02-07 14:52:38 +08:00
 wuwukai007
import time
time.strftime("%W")
#输出 5
#今天 2-7 号不是第七工作周吗?
#日历上工作周是第七周,我用 dayjs 也是输出 7,python 输出是 5 !
2038 次点击
所在节点    Python
7 条回复
welkinzh
2021-02-07 14:56:49 +08:00
?
wuwukai007
2021-02-07 15:01:39 +08:00
@welkinzh 日历上工作周是第七周,我用 dayjs 也是输出 7,python 输出是 5 !
welkinzh
2021-02-07 15:01:44 +08:00
看了一下日历,py 中新年第一周是从第一个周一开始的,确实是第 5 周
okletswin
2021-02-07 15:06:30 +08:00
说明你那个日历够过分的,把去年最后一周算成今年的,还莫非外国习惯把周日当作每周第一天。明天才是第六周
imn1
2021-02-07 15:13:30 +08:00
规则不同而已
1. %W 按 Monday 起始计算,%U 按 Sunday 起始计算
2. 返回结果首序是 0,不是 1
est
2021-02-07 15:26:32 +08:00
https://strftime.org/


Week number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0.
shuax
2021-02-07 17:43:09 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/752075

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX