mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
GH-103857: Deprecate utcnow and utcfromtimestamp (#103858)
Using `datetime.datetime.utcnow()` and `datetime.datetime.utcfromtimestamp()` will now raise a `DeprecationWarning`. We also have removed our internal uses of these functions and documented the change.
This commit is contained in:
parent
a5308e188b
commit
0b7fd8ffc5
10 changed files with 101 additions and 34 deletions
|
|
@ -104,9 +104,9 @@ def time2isoz(t=None):
|
|||
|
||||
"""
|
||||
if t is None:
|
||||
dt = datetime.datetime.utcnow()
|
||||
dt = datetime.datetime.now(tz=datetime.UTC)
|
||||
else:
|
||||
dt = datetime.datetime.utcfromtimestamp(t)
|
||||
dt = datetime.datetime.fromtimestamp(t, tz=datetime.UTC)
|
||||
return "%04d-%02d-%02d %02d:%02d:%02dZ" % (
|
||||
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second)
|
||||
|
||||
|
|
@ -122,9 +122,9 @@ def time2netscape(t=None):
|
|||
|
||||
"""
|
||||
if t is None:
|
||||
dt = datetime.datetime.utcnow()
|
||||
dt = datetime.datetime.now(tz=datetime.UTC)
|
||||
else:
|
||||
dt = datetime.datetime.utcfromtimestamp(t)
|
||||
dt = datetime.datetime.fromtimestamp(t, tz=datetime.UTC)
|
||||
return "%s, %02d-%s-%04d %02d:%02d:%02d GMT" % (
|
||||
DAYS[dt.weekday()], dt.day, MONTHS[dt.month-1],
|
||||
dt.year, dt.hour, dt.minute, dt.second)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue