开发者

Why is it that I cannot insert this into Django correctly?

new_thing = MyTable(last_updated=datetime.datetime.now())
new_thing.save()

>>>>select * from MyTable\G;
last_updated: 2010-04-01 05:26:21

However, in my Python console...this is what it says...

>>> print datetime.datetime.now()
2010-04-01 10:26:21.643041

So obviously it's o开发者_运维百科ff by 5 hours. By the way, the database uses "SYSTEM" as its time, so they should match perfectly.

mysql> SELECT current_time;
+--------------+
| current_time |
+--------------+
| 10:30:16     |
+--------------+
>>> print datetime.datetime.now()
2010-04-01 10:30:17.793040


Difference is between your timezone and whatever is set in Django settings.py TIME_ZONE. By default it's 'America/Chicago'.


I suspect that Django save the time in DB according to GMT and the ORM give it back to you according to your locale.

Tell use what does this code say :

print MyTable.objects.all().order_by("-last_updated")[0].get()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜