0
from datetime import datetime, timedelta dt1 = datetime.strptime("17/02/2016 6:01:26 am(UTC-08:00)", "%d/%m/%Y %H:%M:%S %p(%Z%z)") 

> Traceback (most recent call last): File "<stdin>", line 1, in > <module> File "C:\Python27\lib\_strptime.py", line 317, in _strptime > (bad_directive, format)) ValueError: 'z' is a bad directive in format '%d/%m/%Y %H:%M:%S %p(%Z%z)' 

how to fix this issue?

5
  • Use Python3. That fixed it for me ;) Commented Mar 2, 2016 at 20:39
  • Thanks but I can not change the compiler to fix this issue. I have to stick to the current version. Commented Mar 2, 2016 at 20:42
  • Python 2.7 doesn't support %z: hg.python.org/cpython/file/tip/Lib/_strptime.py#l298 Commented Mar 2, 2016 at 20:46
  • Seems like it will only work on python3: stackoverflow.com/questions/2609259/… Commented Mar 2, 2016 at 20:48
  • 1
    You can do this in Python 2.7: from dateutil.parser import parse; parse("17/02/2016 6:01:26 am(UTC-08:00)".replace("(UTC"," ")[:-1]) Commented Mar 2, 2016 at 20:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.