如何用python在2019-12-17T23:42:20Z中求两个日期

问题描述 投票:-1回答:1

我尝试使用,

Timetaken= 2019-12-18T23:10:45Z - 2019-12-17T23:42:20Z

输出为84505.0

我需要23小时的输出时间

python datetime
1个回答
0
投票

您可以从以下代码获取小时数:

from datetime import datetime

d1 = datetime.strptime("2019-12-20T12:11:37Z", "%Y-%m-%dT%H:%M:%SZ")
d2 = datetime.strptime("2019-12-20T09:04:39Z", "%Y-%m-%dT%H:%M:%SZ")

print(round((d1-d2).seconds / 3600))
© www.soinside.com 2019 - 2024. All rights reserved.