我使用django和一些python代码,但现在我得到了TypeError:不能减去偏移量naive和偏移量感知日期时间
现在我猜django使用欧洲/阿姆斯特丹时区,我不认为我使用python时区。
class SkillTrainingTimer(models.Model):
character = models.ForeignKey(Character, unique=True)
skill = models.ForeignKey(Skill, blank=True)
trainingground = models.ForeignKey(TrainingGround)
timer = models.DateTimeField()
def time_remaining(self):
remaining = datetime.datetime.now() - self.timer
return remaining
如何使用python 2.7添加时区?
文档:链接
import datetime
from django.utils.timezone import utc
def time_remaining(self):
remaining = datetime.datetime.utcnow().replace(tzinfo=utc) - self.timer
return remaining