gpt4 book ai didi

Python添加第二个时间对象

转载 作者:行者123 更新时间:2023-12-04 02:28:58 25 4
gpt4 key购买 nike

<分区>

我需要使用 python datetime 将秒添加到字符串时间,我有以下代码,但出现错误

from datetime import datetime,timedelta

time = "13-15-12"
duration = 15
time_object = datetime.strptime(time, '%H-%M-%S').time()
time_object_end = time_object + timedelta(seconds=duration)

但是报错

time_object_end = time_object + timedelta(seconds=duration)
TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.timedelta'

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com