Python 为什么我的时间错了?

Python 为什么我的时间错了?,python,python-3.x,Python,Python 3.x,这是我的代码: 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(inbetwee

这是我的代码:

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
打印是为了调试。 我试图得到创建时间和当前时间之间的分钟数,但我从一篇不到五分钟的帖子中得到了这样奇怪的值:

2017-09-26 16:11:44
2017-09-26 08:29:22.995548
7:42:21.004452
462.35
27741.004452
True

fromtimestamp()
可能正在传递一个Unix纪元时间,该时间应为UTC(无时区)。但是
now()
在本地时区。要解决此问题,请改用
utcnow()

中间的总时间为479分钟。这意味着创建的时间-当前时间为479分钟。向我们显示创建的时间和当前时间。也许你有时区问题。另外,
time\u created-time\u current
可能应该是反向的。如果定义了
x
,那么
在哪里?是否提交了
。创建了
a
date
对象?如果这篇文章的发布时间少于五分钟,那么
time\u创建时间如何比
time\u current
晚7小时?这就是我们正在展示的<代码>创建的时间=下午4:11,当前时间=当天上午8:29。@JohnZwinck我已经更新了我的帖子,以便它也打印这些变量。