Below is the sample code I am using inside my one of the application. I want Default hour format as 00 (e.g. 02:30:35
) and here I am getting as 0:00:03.011445
so I am using strftime
but I am getting another exception there. Please guide on it.
from datetime import datetime
from datetime import time
from time import strftime
import time
start = datetime.now()
time.sleep(3)
end = datetime.now()
print(start)
print(end)
dt = (end - start)
print('Defual Time:', dt)
print('New Format DateTime', dt.strftime("%m/%d/%y %H:%M:%S"))
I am getting below output.
2020-10-17 19:15:36.831928
2020-10-17 19:15:39.843373
Defualt Time: 0:00:03.011445
Traceback (most recent call last):
File "D:/New folder/IoT2.py", line 30, in <module>
print('New Format DateTime', dt.strftime("%m/%d/%y %H:%M:%S"))
AttributeError: 'datetime.timedelta' object has no attribute 'strftime'