What is the module/method used to get the current time?
This question is for Python but since Django is one of the most widely used frameworks for Python, its important to note that if you are using Django you can always use timezone.now()
instead of datetime.datetime.now()
. The former is timezone 'aware' while the latter is not.
See this SO answer and the Django doc for details and rationale behind timezone.now()
.
from django.utils import timezone
now = timezone.now()