Da:Come aggiungere delta a python datetime.time?
http://docs.python.org/py3k/library/datetime.html#timedelta-objects
A timedelta object represents a duration, the difference between two dates or times.
Allora perché ottengo l'errore con questo:
>>> from datetime import datetime, timedelta, time
>>> datetime.now() + timedelta(hours=12)
datetime.datetime(2012, 9, 17, 6, 24, 9, 635862)
>>> datetime.now().date() + timedelta(hours=12)
datetime.date(2012, 9, 16)
>>> datetime.now().time() + timedelta(hours=12)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.timedelta'
È molto lavoro. Voglio solo calcolare un time shift, python :). tuttavia è una soluzione, grazie. – xliiv
Una cosa da notare qui è che se 't' è più piccolo di' delta', quindi, si finirà con 'dt.date (1,1,0)', che è un 'OverflowError: valore di data fuori intervallo '. Un modo per avvicinarsi a questo è aumentare i valori in 'dt.date (...)'. Ma questo è ancora un problema con cui bisogna stare attenti. – Akavall