简体   繁体   中英

Django: How to retrieve datetime as timezone-aware

At one point in my program, I save a timezone aware (ISO8601 with Z) datetime:

param.updated=iso8601.parse_date(updated)
param.save

Later, I retrieve it to do a comparison:

if (newparam.update > Parameter.objects.get(id=id).updated):
....

Result:

TypeError: can't compare offset-naive and offset-aware datetimes

What am I doing wrong? Am I losing the timezone-awareness when I'm saving, or when I retrieve? How can I restore it?

Python 2.6.x, Django 1.3

Django的1.4对时区的支持,检查出。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM