V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wuwukai007
V2EX  ›  Python

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

  •  
  •   wuwukai007 · 2021-02-07 14:52:38 +08:00 · 2004 次点击
    这是一个创建于 1145 天前的主题,其中的信息可能已经有所发展或是发生改变。
    import time
    time.strftime("%W")
    #输出 5
    #今天 2-7 号不是第七工作周吗?
    #日历上工作周是第七周,我用 dayjs 也是输出 7,python 输出是 5 !
    
    7 条回复    2021-02-07 17:43:09 +08:00
    welkinzh
        1
    welkinzh  
       2021-02-07 14:56:49 +08:00
    ?
    wuwukai007
        2
    wuwukai007  
    OP
       2021-02-07 15:01:39 +08:00
    @welkinzh 日历上工作周是第七周,我用 dayjs 也是输出 7,python 输出是 5 !
    welkinzh
        3
    welkinzh  
       2021-02-07 15:01:44 +08:00
    看了一下日历,py 中新年第一周是从第一个周一开始的,确实是第 5 周
    okletswin
        4
    okletswin  
       2021-02-07 15:06:30 +08:00
    说明你那个日历够过分的,把去年最后一周算成今年的,还莫非外国习惯把周日当作每周第一天。明天才是第六周
    imn1
        5
    imn1  
       2021-02-07 15:13:30 +08:00   ❤️ 1
    规则不同而已
    1. %W 按 Monday 起始计算,%U 按 Sunday 起始计算
    2. 返回结果首序是 0,不是 1
    est
        6
    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
        7
    shuax  
       2021-02-07 17:43:09 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1242 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 23:25 · PVG 07:25 · LAX 16:25 · JFK 19:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.