How to add delta to python datetime.time?

后端 未结 5 1970
别那么骄傲
别那么骄傲 2020-11-27 06:46

From:

http://docs.python.org/py3k/library/datetime.html#timedelta-objects

A timedelta object represents a duration, the difference between two

5条回答
  •  眼角桃花
    2020-11-27 07:06

    Here is a function that adds a time to a timedelta:

    def time_plus(time, timedelta):
        start = datetime.datetime(
            2000, 1, 1,
            hour=time.hour, minute=time.minute, second=time.second)
        end = start + timedelta
        return end.time()
    

    This will provide the expected result so long as you don't add times in a way that crosses a midnight boundary.

提交回复
热议问题