datetime.datetime.now() returns wrong time on Windows when env var TZ is set
未关闭
还没有人认领这个 Issue。
stdlib
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Europe/Berlin is UTC+2 right now, not UTC+1
Works fine on Linux OSes (builds).
C:\Users\work>python
Python 3.12.6 (tags/v3.12.6:a4a2d2b, Sep 6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['TZ'] = 'Europe/Berlin'
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2024, 9, 20, 12, 15, 24, 771320)
>>> datetime.datetime.now(tz=datetime.UTC)
datetime.datetime(2024, 9, 20, 11, 15, 45, 162005, tzinfo=datetime.timezone.utc)
>>>
CPython versions tested on:
3.12
Operating systems tested on:
Windows
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,在将 TZ 设置为 Europe/Berlin 的 Windows 上复现所报告的 Python 3.12 行为,并比较 datetime.datetime.now() 与 datetime.datetime.now(tz=datetime.UTC)。跟踪涉及的 datetime 和 Windows 时区处理;当本地时间反映正确的柏林偏移量,并且该行为有回归测试覆盖时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100