i am having a small program that gets time from system and dose some arithemetic on it. here is my code:
import time
import datetime
c_time = time.strftime("%H:%M;%S")
# now to convert it into time object i am using
c_time_converted = datetime.datetime.strptime(c_time,"%H:%M;%S")
print c_time_converted
the output is of the form :
1900-01-01 11:39:40 but i want only the time part when i split and perform other operations on it i get a string returned but i need in time format so that i can perform time arethemetic
i want it in form 11: 39:40
Just use .time():
prints:
EDIT (addressing a comment regarding datetime)
Here is a simple example of using a difference in datetime:
prints:
0:36:24
now we will add
dt
time back toc_time
above and see that we recoverc_time_later
:prints:
23:50:21
Or add an hour using timedelta: