1

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.

2 Answers 2

6

But I don't want to 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())
Sign up to request clarification or add additional context in comments.

Comments

1

To parse rfc 822 time string that is used in email, http, and other internet protocols, you could use email stdlib module:

#!/usr/bin/env python
from email.utils import parsedate_tz, mktime_tz

timestamp = mktime_tz(parsedate_tz("Wed, 18 May 2016 11:21:35 GMT"))

See Converting string to datetime object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.