的,不要取出這麼多的信息。留在:
冒號(你的正則表達式將它們刪除,但我敢打賭,在你將它們擊倒之前,它們在那裏)。如果有時間分隔符,你的日期解析得很好:
>>> from dateutil.parser import parse
>>> date1 = 'Tue Feb 10 2015 12 52pm IST'
>>> parse(date1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mpieters/Development/venvs/stackoverflow-2.7/lib/python2.7/site-packages/dateutil/parser.py", line 743, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "/Users/mpieters/Development/venvs/stackoverflow-2.7/lib/python2.7/site-packages/dateutil/parser.py", line 310, in parse
ret = default.replace(**repl)
ValueError: hour must be in 0..23
>>> date1_with_colon = 'Tue Feb 10 2015 12:52pm IST'
>>> parse(date1_with_colon)
datetime.datetime(2015, 2, 10, 12, 52)
>>> date2_with_colon = '10 February 15 08:35am'
>>> parse(date2_with_colon)
datetime.datetime(2015, 2, 10, 8, 35)
>>> date3_with_colon = '2015 02 10 08:24:26 UTC'
>>> parse(date3_with_colon)
datetime.datetime(2015, 2, 10, 8, 24, 26, tzinfo=tzutc())