这是我的代码:
x = 10
def get_date(submission):
time = submission.created
time_created = datetime.datetime.fromtimestamp(time)
time_current = datetime.datetime.now()
inbetween = time_created - time_current
inbetween_total = int(inbetween.total_seconds()) / 60
# If submission is older than 10 minutes, return True, if it isn't, return false
if inbetween_total > x:
print(time_created)
print(time_current)
print(inbetween)
print(inbetween_total)
print(inbetween.total_seconds())
return True
else:
print(inbetween)
print(inbetween_total)
print(inbetween.total_seconds())
return False
打印用于调试。 我试图在time_created和time_current之间得到分钟,但是我从不到五分钟的老帖子中得到这样的奇怪值:
2017-09-26 16:11:44
2017-09-26 08:29:22.995548
7:42:21.004452
462.35
27741.004452
True
答案 0 :(得分:1)
fromtimestamp()
可能正在传递一个Unix纪元时间,该时间应该是UTC(没有时区)。但now()
位于当地时区。要解决此问题,请改用utcnow()
。