The basic date type of Python is ISO 8601 and has the following format
2017-08-25 18:57:07.602290
RFC822, on the other hand, has the following format
Fri, 25 Aug 2017 09:57:07 -0000
Here's how to convert ISO 8601 to RFC 822 in Python
python
import datetime
import time
from email import utils
now = datetime.datetime.now()
# 2017-08-25 18:57:07.602290
nowtuple = now.timetuple()
# time.struct_time(tm_year=2017, tm_mon=8, tm_mday=25, tm_hour=18, tm_min=57, tm_sec=7, tm_wday=4, tm_yday=237, tm_isdst=-1)
nowtimestamp = time.mktime(nowtuple)
# 1503655027.0
rfc822 = utils.formatdate(nowtimestamp)
print(rfc822)
# Fri, 25 Aug 2017 09:57:07 -0000
Recommended Posts