0

I am trying to parse date which have string format as

u'June 11, 2015 - 12:26 hrs IST'

but when I am using dateutil parser to parse I am getting error.

 from dateutil.parser import parse
 parse("u'June 11, 2015 - 12:26 hrs IST'")

Here is the error traceback.

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/rranjan/.virtualenvs/crawler/lib/python2.7/site-packages/dateutil/parser.py", line 982, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/Users/rranjan/.virtualenvs/crawler/lib/python2.7/site-packages/dateutil/parser.py", line 390, in parse
    raise ValueError("Unknown string format")
ValueError: Unknown string format
4

1 回答 1

0

I was experimenting with different formats and finally, when I removed hrs from the date string, it worked.

 from dateutil.parser import parse
 parse("June 11, 2015 - 12:26 IST")

 // this gives
 datetime.datetime(2015, 6, 11, 12, 26, tzinfo=tzlocal())

To learn more what dateutil formatting requirement is, follow this link.

于 2017-04-03T19:40:33.693 回答