使用 python 以小时为单位比较两次

Comparing two times in Hours using python

我有两个日期,时区格式为 ('%Y-%m-%dT%H:%M:%SZ')

Given_Time = '2020-02-12T02:12:12Z'
current_time = '2020-02-11T06:22:42Z' 

我想在小时内比较这两个时间。我的意思是给定的日期是比当前时间晚多少小时

import datetime
def time_diff(x, y):
     x = datetime.datetime.strptime(x,'%Y-%m-%dT%H:%M:%SZ')
     y = datetime.datetime.strptime(y,'%Y-%m-%dT%H:%M:%SZ')
     return (x-y).total_seconds()/3600

time_diff(Given_Time, current_time)
19.825
time_diff(current_time, Given_Time)
-19.825