我正在使用以下格式将字符串转换为日期时间对象。
datetime.datetime.strptime(systemTime, '%a %b %d %H:%M:%S %Z %Y')
我对其进行了测试,systemTime="Wed Jan 05 06:10:01 GMT 2005"
并且效果很好。但是当我尝试时systemTime="Wed Oct 02 18:01:56 EDT 2013"
,它失败了ValueError
:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "SimpleWebServer.py", line 146, in startUDPServer
ESTTime = datetime.datetime.strptime(systemTime, '%a %b %d %H:%M:%S %Z %Y')
File "/usr/lib/python2.7/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data 'Wed Oct 02 18:01:56 EDT 2013' does not match format '%a %b %d %H:%M:%S %Z %Y'
机器上的语言环境是“en US”。我的格式有什么问题吗?