HTTP Datetime Format
Recipes
RFC 5322 Format (RFC 2822 obsoleted).
import email.utils
import time
from datetime import datetime, timezone
# timestamp
>>> timestamp = time.time()
>>> email.utils.formatdate(timestamp, usegmt=True)
'Fri, 12 Aug 2022 13:56:40 GMT'
# datetime
>>> dt = datetime.now(timezone.utc)
>>> email.utils.format_datetime(dt, usegmt=True)
'Fri, 12 Aug 2022 13:56:40 GMT'
References
- RFC 5322 - Internet Message Format (obsolete RFC 2822)
- RFC 9110 - HTTP Semantics (2022.6) (obsolete RFC 7231)