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?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
newday
  • 3,842
  • 10
  • 54
  • 79
  • Use Python3. That fixed it for me ;) – zondo Mar 02 '16 at 20:39
  • Thanks but I can not change the compiler to fix this issue. I have to stick to the current version. – newday Mar 02 '16 at 20:42
  • Python 2.7 doesn't support `%z`: https://hg.python.org/cpython/file/tip/Lib/_strptime.py#l298 – Alex Mar 02 '16 at 20:46
  • Seems like it will only work on python3: http://stackoverflow.com/questions/2609259/converting-string-to-datetime-object-in-python – Jan Mar 02 '16 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])` – Alex Mar 02 '16 at 20:52

0 Answers0