【发布时间】:2020-02-12 02:23:57
【问题描述】:
我有两个日期的时区格式为 ('%Y-%m-%dT%H:%M:%SZ')
Given_Time = '2020-02-12T02:12:12Z'
current_time = '2020-02-11T06:22:42Z'
我想在 Hrs 中比较这两次。我的意思是给定日期比当前时间晚多少小时
【问题讨论】:
标签: python-3.x date time utc
我有两个日期的时区格式为 ('%Y-%m-%dT%H:%M:%SZ')
Given_Time = '2020-02-12T02:12:12Z'
current_time = '2020-02-11T06:22:42Z'
我想在 Hrs 中比较这两次。我的意思是给定日期比当前时间晚多少小时
【问题讨论】:
标签: python-3.x date time utc
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
【讨论】: