Skip to the content.

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