【发布时间】:2019-02-06 23:51:22
【问题描述】:
我一直在尝试将 apache 日志中的日期格式转换为 Python 3 中的 ISO 格式,但我似乎无法让它工作。
如果我只包含天、月和年,而不是小时、分钟和秒,我可以让它工作。
Text = "25/Jan/2000:14:00:01"
Date = dateutil.parser.parse(Text)
Date = Date.isoformat()
print(Date)
# I receive the following error messages below
Traceback (most recent call last):
File "Z:/Test.py", line 3, in <module>
Date = dateutil.parser.parse(Text)
File "Z:\Python\lib\site-packages\dateutil\parser\_parser.py", line 1356, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "Z:\Python\lib\site-packages\dateutil\parser\_parser.py", line 648, in parse
raise ValueError("Unknown string format:", timestr)
ValueError: ('Unknown string format:', '25/Jan/2000:14:00:01'
我也尝试过使用 datetime 模块 (datetime.datetime.strftime()) 但出现了同样的问题。
有人可以帮帮我吗?
【问题讨论】:
标签: python-3.x python-datetime python-dateutil