I
I
Imbolc2012-04-22 06:27:43
Django
Imbolc, 2012-04-22 06:27:43

Django timezones?

What is the difference between datetime.now() and datetime.utcnow() in django?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DmZ, 2012-04-22
@DmZ

In python, everything is perfectly described in the documentation :

classmethod datetime.now([tz]) : Return the current local date and time.
classmethod datetime.utcnow() : Return the current UTC date and time, with tzinfo None.

Those. now() returns the time taking into account the timezone, and utcnow() returns in UTC: Django also has everything perfectly described in the documentation , with the addition that if the use of timezones is enabled (USE_TZ=True, usually enabled), then at the DB level will be used types that can store timezone information.
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2012, 4, 22, 8, 51, 41, 549137)
>>> datetime.datetime.utcnow()
datetime.datetime(2012, 4, 22, 5, 51, 49, 174015)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question