Enhancement Proposal: Standardized Support for Non-Zero-Padded Day and Month Formatting in datetime.strftime
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Feature or enhancement
Proposal:
Python's datetime.datetime.strftime supports formatting directives for dates and times, such as %d for zero-padded days and %m for zero-padded months.
While there are platform-specific ways to get non-zero-padded day (%-d on Unix) or month (%-m), these do not work reliably across all platforms.. Particularly between Unix-like systems and Windows.
from datetime import datetime
dt = datetime(2025, 6, 6)
# On Unix:
dt.strftime("%-d. %-m. %Y") # '6. 6. 2025'
# On Windows:
dt.strftime("%-d. %-m. %Y") # Raises ValueError
I understand that strftime relies on the underlying C library for formatting, which is probably why this behavior differs between platforms. That said, if it's not practical to change this at the core level, maybe there could be some kind of wrapper or Python-level normalization to make things more consistent across systems.
Currently this requires a workaround such as usage of .format directly on the datetime object.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
- gh-138982
- gh-139002
- gh-139088
- gh-145018
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 datetime.datetime.strftime 开始,调查其指令在类 Unix 系统和 Windows 上如何依赖底层 C 库。在开始之前查看已链接的 PRs;确定一种在各平台上对不带前导零的日和月进行格式化的一致方案,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- operating-systems
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 20/100