python - 使用 Python 将 ISO 8601 时间格式计算为小时/分钟

标签 python datetime time

我如何接收字符串输入(ISO 8601 格式的时间)并转换/计算从那时到现在的持续时间?

输入:2018-09-29T00:33:33Z

输出:3 天前

谢谢。

最佳答案

from datetime import datetime
import dateutil.parser

a = datetime.now()
#a = datetime.strftime(a, format="%Y-%m-%d%H:%M:%S")
#a = a[:10] + 'T' + a[10:] + 'Z'
a = datetime.strftime(a, format="%Y-%m-%dT%H:%M:%SZ")

a = dateutil.parser.parse(a) - dateutil.parser.parse("2018-09-29T00:33:33Z")
print(str(a))

3 days, 2:00:00

关于python - 使用 Python 将 ISO 8601 时间格式计算为小时/分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52600890/

相关文章:

php - 在 PHP 中减去时间

PHP datetime 添加一秒

Android - 找出现在是几点钟

python - 使用 <> 条件合并 2 个数据帧

jquery - 使用 jquery 和 Json 时日期值显示格式错误

python - 无法在 Keras 中使用 VGG19 预测单个图像的标签

r - 如何转换时间和日期

java - 如何获取当前时间 09 :04:15 instead of 9:4:15 when using Date?

python - 为什么类的新实例与其他实例共享成员?

用于分布式拍卖模拟的python包