<p>下面是一种方法,您可以在评论中进行一些解释:</p>
<pre><code>from datetime import datetime, timezone
air_time_GMT = '2020-08-05 13:30:00'
# Python will assume your input is local time if you don't specify a time zone:
air_time = datetime.strptime(air_time_GMT, '%Y-%m-%d %H:%M:%S')
# ...so let's do this:
air_time = air_time.replace(tzinfo=timezone.utc) # using UTC since it's GMT
# again, if you don't supply a time zone, you will get a datetime object that
# refers to local time but has no time zone information:
current_time = datetime.now()
# if you want to compare this to a datetime object that HAS time zone information,
# you need to set it here as well. You can set local time zone via
current_time = current_time.astimezone()
print(current_time)
print(air_time-current_time)
>>> 2020-08-05 14:11:45.209587+02:00 # note that my machine is on UTC+2 / CEST
>>> 1:18:14.790413
</code></pre>
<p>我想你应该注意两件事</p>
<ul>
<li>首先,Python默认假定datetime对象属于本地时间(OS时区设置),如果它是原始的(没有时区信息)</李>
<li>其次,您不能将<em>naive</em>日期时间对象(未定义时区/UTC偏移量)与<em>aware</em>日期时间对象(给定时区信息)进行比较</李>
</ul>
<p><a href="https://docs.python.org/3/library/datetime.html" rel="nofollow noreferrer">[datetime module docs]</a></p>