我正在尝试对以下形式的字符串进行日期时间格式编码:“06JAN2018”或“31DEC2017”。
我认为这是 format = '%d[xxxx]%Y' 但我不知道如何对其月份部分进行编码。
是否有可能的每种编码类型的列表?
Bra*_*mon 10
这些代码的列表位于datetime
模块的strftime() 和 strptime() 行为文档中。
\n\n\n\n
%b
:月份为 locale\xe2\x80\x99s 缩写名称。
在你的情况下,06JAN2018
是%d%b%Y
.
如果您实际上想要做的是将日期时间对象或 Pandas/NumPy 日期时间数组编码为字符串,您可能需要自己进行大写:
\n\n>>> dt = datetime.datetime(2017, 12, 31)\n>>> dt.strftime(\'%d%b%Y\').upper() # or .str.upper() in Pandas\n\'31DEC2017\'\n
Run Code Online (Sandbox Code Playgroud)\n