do not use datetime.today()

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: python-best-practices/no-datetime-today

Language: Python

Severity: Notice

Category: Best Practices

Description

Avoid using datetime.today() and use instead datetime.now(). The two calls are equivalent (as mentioned in the official documentation) and the use of now() is more explicit than today().

Using today() makes you think it only returns the year/month/day but it returns a full timestamp. For this reason, prefer using now().

Non-Compliant Code Examples

from datetime import datetime
print("foo")
bla = datetime.today()  # use datetime.now() instead

Compliant Code Examples

from datetime import datetime
print("foo")
bla = datetime.now()
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis