ValueError when using strptime to get a datetime object

I am trying to convert a date string to a datetime object as shown below:

dt = datetime.datetime.strptime('2011-07-15 13:00:00+00:00', '%Y-%m-%d %H:%M:%S')

But, im getting the error below:

Traceback (last last call): File ", line 1, to File" / usr / lib / python 2.6 / _strptime.py ", line 328, to _strptime data_string [found.end ():]) ValueError: uncured data remains: +00: 00

I think there is a problem with my format string. How to fix it?

thank

+5
source share
3 answers

What about...

    dt_string = '2011-07-15 13:00:00+00:00'
    new_dt = dt_string[:19]
    dt = datetime.datetime.strptime(new_dt, '%Y-%m-%d %H:%M:%S')
+3
source

dt = datetime.datetime.strptime ('2011-07-15 13: 00: 00 + 00: 00', '% Y-% m-% d% H:% M:% S +% z')

0
source
>>> datetime.datetime.strptime('2011-07-15 13:00:00', '%Y-%m-%d %H:%M:%S'
datetime.datetime(2011, 7, 15, 13, 0)
-5

All Articles