MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / format_datetime

Function format_datetime

tools/python-3.11.9-amd64/Lib/email/utils.py:155–171  ·  view source on GitHub ↗

Turn a datetime into a date string as specified in RFC 2822. If usegmt is True, dt must be an aware datetime with an offset of zero. In this case 'GMT' will be rendered instead of the normal +0000 required by RFC2822. This is to support HTTP headers involving date stamps.

(dt, usegmt=False)

Source from the content-addressed store, hash-verified

153 return format_datetime(dt, usegmt)
154
155def format_datetime(dt, usegmt=False):
156 """Turn a datetime into a date string as specified in RFC 2822.
157
158 If usegmt is True, dt must be an aware datetime with an offset of zero. In
159 this case 'GMT' will be rendered instead of the normal +0000 required by
160 RFC2822. This is to support HTTP headers involving date stamps.
161 """
162 now = dt.timetuple()
163 if usegmt:
164 if dt.tzinfo is None or dt.tzinfo != datetime.timezone.utc:
165 raise ValueError("usegmt option requires a UTC datetime")
166 zone = 'GMT'
167 elif dt.tzinfo is None:
168 zone = '-0000'
169 else:
170 zone = dt.strftime("%z")
171 return _format_timetuple_and_zone(now, zone)
172
173
174def make_msgid(idstring=None, domain=None):

Callers 1

formatdateFunction · 0.85

Calls 3

timetupleMethod · 0.45
strftimeMethod · 0.45

Tested by

no test coverage detected