Home > Blockchain >  How to add datetime.time to datetime.datetime
How to add datetime.time to datetime.datetime

Time:02-20

I have both a Python datetime.datetime object and a datatime.time object and am looking for a way to add the time to the datetime object.

A simple addition doesn't seem to be supported. The time is essentially representing a duration.

CodePudding user response:

Hi let's suppose that you have an instance t of class datetime.time and an instance dt of class datetime.datetime:

new_dt = dt   datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second, microseconds=t.microsecond)
  • Related