maikelm maikelm - 6 months ago 63
Python Question

Python convert date string to timestamp

I need to convert string type Wed, 18 May 2016 11:21:35 GMT to timestamp, in Python. I'm using:

datetime.datetime.strptime(string, format)


But I don't want to specify the format for the date type.

Answer

But I like not specify the format for the date type.

Then, let the dateutil parser figure that out:

>>> from dateutil.parser import parse
>>> parse("Wed, 18 May 2016 11:21:35 GMT")
datetime.datetime(2016, 5, 18, 11, 21, 35, tzinfo=tzutc())