We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Subsequent datetime.now() may return the same moment in time.
datetime.now()
from datetime import datetime, UTC now1 = datetime.now(UTC) for i in range(10_000): a = i now2 = datetime.now(UTC) assert now1 < now2
assert now1 < now2 ^^^^^^^^^^^ AssertionError
This does seem to work as expected:
from time import sleep from datetime import datetime, UTC now1 = datetime.now(UTC) sleep(0.000_000_001) now2 = datetime.now(UTC) assert now1 < now2
I'm not sure if this is a bug, but at least it's a documentation issue. There's nothing in the docs explicitly indicating this behavior.
3.12
Windows
datetime.now
Bug report
Bug description:
Subsequent
datetime.now()may return the same moment in time.This does seem to work as expected:
I'm not sure if this is a bug, but at least it's a documentation issue.
There's nothing in the docs explicitly indicating this behavior.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
datetime.nowmay return the same instant #124834datetime.nowmay return the same instant (GH-124834) #125145datetime.nowmay return the same instant (GH-124834) #125146