You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中datetime.now().strftime("%j")的功能是什么?

Python datetime.strftime中%j格式符的作用

我使用datetime模块获取当前年份时,用datetime.now().strftime("%Y")可以得到预期的2023,但把参数换成%j时,返回了309,想知道%j的作用是什么?

from datetime import datetime

print(datetime.now().strftime("%Y")) #Returns current year (2023)
print(datetime.now().strftime("%j")) #Returns 309

%j是strftime方法的日期格式符,用来表示当前日期在当年的第几天,格式为三位数字:

  • 每年1月1日对应001
  • 平年12月31日对应365,闰年则对应366

你得到的309就代表执行代码的当天是这一年的第309天。

内容的提问来源于stack exchange,提问作者Dinux

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 23:28:08