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

Function formatdate

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

Returns a date string as specified by RFC 2822, e.g.: Fri, 09 Nov 2001 01:08:47 -0000 Optional timeval if given is a floating point time value as accepted by gmtime() and localtime(), otherwise the current time is used. Optional localtime is a flag that when True, interpret

(timeval=None, localtime=False, usegmt=False)

Source from the content-addressed store, hash-verified

124 zone)
125
126def formatdate(timeval=None, localtime=False, usegmt=False):
127 """Returns a date string as specified by RFC 2822, e.g.:
128
129 Fri, 09 Nov 2001 01:08:47 -0000
130
131 Optional timeval if given is a floating point time value as accepted by
132 gmtime() and localtime(), otherwise the current time is used.
133
134 Optional localtime is a flag that when True, interprets timeval, and
135 returns a date relative to the local timezone instead of UTC, properly
136 taking daylight savings time into account.
137
138 Optional argument usegmt means that the timezone is written out as
139 an ascii string, not numeric one (so "GMT" instead of "+0000"). This
140 is needed for HTTP, and is only used when localtime==False.
141 """
142 # Note: we cannot use strftime() because that honors the locale and RFC
143 # 2822 requires that day and month names be the English abbreviations.
144 if timeval is None:
145 timeval = time.time()
146 if localtime or usegmt:
147 dt = datetime.datetime.fromtimestamp(timeval, datetime.timezone.utc)
148 else:
149 dt = datetime.datetime.utcfromtimestamp(timeval)
150 if localtime:
151 dt = dt.astimezone()
152 usegmt = False
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.

Callers 1

datetime_to_headerFunction · 0.90

Calls 5

format_datetimeFunction · 0.85
utcfromtimestampMethod · 0.80
astimezoneMethod · 0.80
timeMethod · 0.45
fromtimestampMethod · 0.45

Tested by

no test coverage detected