strftime返回ValueError

问题描述 投票:-2回答:1

strftime返回值错误。为什么?这是代码

datetime.datetime.now().strftime('%-m')

我的输出:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid format string
python datetime
1个回答
1
投票
基于strftime.org格式可以取决于系统。

[在Unix上,可能需要-之类的"%-m",但在Windows上可能需要#之类的"%#m"

我只能在Linux上进行测试,并且两者都对我有用:"%-m %#m"


BTW:,但如果要获取负值,则需要像-]一样在%之前需要[C0

© www.soinside.com 2019 - 2024. All rights reserved.