Python Forum
time issue - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: time issue (/thread-22653.html)



time issue - deepakkr3110 - Nov-21-2019

this is my python code
dateTimeObj = datetime.now()
timestampStr = dateTimeObj.strftime("%d/%b/%Y:%H:%M:%S")
print'Today Current Timestamp : ', timestampStr

and i want to print last 10 second
like current time - last ten second. can any one tell me how can i do so?


RE: time issue - perfringo - Nov-21-2019

Something like this?

>>> from datetime import datetime, timedelta                                               
>>> now = datetime.now()                                                                   
>>> now                                                                                    
datetime.datetime(2019, 11, 21, 12, 51, 51, 588650)
>>> deducted = now - timedelta(seconds=10)                                                 
>>> deducted                                                                               
datetime.datetime(2019, 11, 21, 12, 51, 41, 588650)