0
start_time=datetime.time(9,00)
new_time=starttime+datetime(0,50) # I want new time as 9.50

但这会给我一个错误:

TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.time'
4

2 回答 2

3

请尝试以下 python 脚本:

from datetime import datetime
from datetime import timedelta 
time = datetime(2013, 5, 31, 03, 00, 00)###or you can use time = datetime.datetime.now() 

diff = timedelta(seconds = 60)

final_time = time + diff
print final_time
于 2013-05-31T09:25:13.537 回答
-1

我们可以重载操作符,做上面的功能,请检查下面的代码

class Mytime(datetime.time):
    def __add__(self,b):
        res = (self.hour*60+self.minute)+(b.hour*60+b.minute)
        return Mytime(res/60,res%60)

start_time = Mytime(9,0)
next_time = start_time+Mytime(9,0)
于 2013-05-31T09:25:47.907 回答