Reference Python 标准库 reference

Python datetime.date.today 参考

Python datetime.date.today 参考,整理标准库调用语法、参数、示例、返回值和常见错误。

语法

python
from datetime import date

today = date.today()

参数

  • value:日期时间字符串、时间戳或 datetime/date 对象。
  • format / tzinfo:解析格式或时区设置。

返回值

返回 datetime/date/timedelta 对象、时间戳或格式化字符串。

示例

python
from datetime import date

print(date.today())

常见错误

  • 解析格式和输入字符串不一致会抛出 ValueError。
  • 混用有时区和无时区时间会导致比较或计算报错。

相关内容