python - strftime 返回 ValueError
问题描述
strftime 返回值错误。为什么?
这是代码
datetime.datetime.now().strftime('%-m')
我的输出:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid format string
解决方案
基于strftime.org格式可以依赖系统。
在 Unix 上可能需要-
like"%-m"
但在 Windows 上可能需要#
like "%#m"
.
我只能在 Linux 上对其进行测试,并且两者都对我有用:"%-m %#m"
顺便说一句:但如果你想获得负值,那么你需要-
先%
喜欢"-%m"
推荐阅读
- logstash - 无法将多行 json 数据解析为 logstash
- javascript - 有条件地将 x 个数组项推送到另一个数组
- python - 查找列中每个值之间的中点(Python)
- powershell - Powershell 比较 2 个对象上的 2 个 csv 文件并上传 3 个文件
- r - 在 if 条件 %in% 操作期间加速 R 的 grep
- assembly - VS2019 编译 asm 时无法打开文件 .obj
- fortran - 错误: (1) 处的不可分类声明?在 do while 语句下的行
- c# - WPF C# DataGrid - 检测用户在尝试保存整个文件时尚未在一行上按回车键
- javascript - Javascript导致某些链接不起作用
- laravel - 当我使用 laravel 的 DB 外观进行简单连接时,我得到了与结果相同的行