django python datetime朴素且有意识
我正在使用django和一些python代码,但现在我得到了TypeError:不能减去偏移量naive和偏移量感知的日期时间 现在我猜django使用的是欧洲/阿姆斯特丹时区,我不认为我使用python的时区django python datetime朴素且有意识,django,datetime,timezone,Django,Datetime,Timezone,我正在使用django和一些python代码,但现在我得到了TypeError:不能减去偏移量naive和偏移量感知的日期时间 现在我猜django使用的是欧洲/阿姆斯特丹时区,我不认为我使用python的时区 class SkillTrainingTimer(models.Model): character = models.ForeignKey(Character, unique=True) skill = models.ForeignKey(Skill, blank=Tru
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