为什么这个字符串解析为日期?

时间:2018-06-17 14:09:22

标签: python date

这让我发疯了。我看了看并查看了strptime文档,并且不能为我的生活弄清楚为什么这不起作用。请帮忙!

import datetime    
a = '20180615 16:00 EST'
datetime.datetime.strptime(a, '%Y%m%d %H:%M %Z')

Traceback (most recent call last):
          File "/usr/local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
            exec(code_obj, self.user_global_ns, self.user_ns)
          File "<ipython-input-30-d72261c0e1d6>", line 1, in <module>
            datetime.datetime.strptime(a, '%Y%m%d %H:%M %Z')
          File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
            tt, fraction = _strptime(data_string, format)
          File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_strptime.py", line 362, in _strptime
            (data_string, format))
        ValueError: time data '20180615 16:00 EST' does not match format '%Y%m%d %H:%M %Z'

0 个答案:

没有答案