我正在尝试计算帖子上线后的小时数。它有效,除了它将 24 小时后视为 0 小时。换句话说,它似乎只是从基线时间中减去当前时间,而没有考虑日差。
def hours_live(self):
diff=((datetime.datetime.today() - self.created).seconds)/3600
return '%d Hours Ago' %diff
self.created 引用 Django DateTimeField:
created=models.DateTimeField(auto_now_add=True)
这里的日期时间对象我遗漏了什么?
请您参考如下方法:
您需要total_seconds(),而不是seconds。
