[英]Django: How to retrieve datetime as timezone-aware
At one point in my program, I save a timezone aware (ISO8601 with Z) datetime: 在程序的某一时刻,我保存了一个时区感知(带有Z的ISO8601)日期时间:
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 Python 2.6.x,Django 1.3
Django的1.4对时区的支持,检查这出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.