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()
精彩评论