我的日期格式为德语,例如,
2. Okt. 2009
Run Code Online (Sandbox Code Playgroud)
也许也是
2. Oct. 2009
Run Code Online (Sandbox Code Playgroud)
如何将其解析为ISO datetime(或python datetime)?
通过使用此代码段解决:
for l in locale.locale_alias:
worked = False
try:
locale.setlocale(locale.LC_TIME, l)
worked = True
except:
worked = False
if worked: print l
Run Code Online (Sandbox Code Playgroud)
然后在setlocale中插入适当的参数l.
可以解析使用
import datetime
print datetime.datetime.strptime("09. Okt. 2009", "%d. %b. %Y")
Run Code Online (Sandbox Code Playgroud)