-1

I am looking for a pythonic way of parsing a datetime object into an RFC 1132 compliant string:

Assuming (GMT)

So: 2008-10-22T10:52:40Z into Wed, 22 Oct 2008 10:52:40 GMT

I am sure there is a very simple way but i haven't been able to find it.

Thanks

RHSMan
  • 157
  • 2
  • 15

1 Answers1

1

I could advise something like this:

from datetime import datetime
import pytz

date_str = '2008-10-22T10:52:40Z'

mytime = datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%SZ")
mytime = mytime.replace(tzinfo=pytz.timezone('GMT'))
print(mytime.strftime("%a, %d %b %Y %H:%M:%S %Z"))
# Output: Wed, 22 Oct 2008 10:52:40 GMT

List of formatting directives for strftime you could find here.

Roman Alexeev
  • 339
  • 3
  • 16