Hyunseo Yang
Hyunseo Yang

Reputation: 161

why the time is different from my TIME_ZONE in settings.py

I'm using Sqlite for my project database. I need date and time in my model so i'm using this field.

date = models.DateTimeField()

On the result template(results.html), the time is correct (localtime or TIME_ZONE in my settings.py) The problem is, when i check the database on Django admin page and sqlite db file, it seems like my timezone setting is not applied.(so, maybe UTC)

What is the problem and how could i fix this?

I think the template's parameters are from view, so the timezone.now() is correct and passes the right time. So my guess is that 'date=timezone.now()' passes to sqlite like this:

insert into table values (date=datetime('now'))'

and the timezone of sqlite is maybe set to UTC default.

This is what i'm guessing. Am i right? Also i do not know how to set sqlite database timezone...

p.s On the other side, I also think when we set settings.py TIME_ZONE, django would manage all these things. So don't know where to approach. Spending almost 2 days on this problem...

Upvotes: 3

Views: 2072

Answers (1)

KongDeqiang
KongDeqiang

Reputation: 183

In settings.py, set

USE_TZ = False

can fix this problem

Upvotes: 8

Related Questions