NOTE: I am not trying to find the elapsed time of my program running. I found tons of examples of that on Google, but it didn't really help me out.
Here is my code to receive and validate the times (to make sure they are real times):
import time timex = '0103' timex2 = '2003' timeResult = None for format in ['%H%M']: try: timeResult = time.strptime(timex, format) timeResult2 = time.strptime(timex2, format) except: pass if timeResult is None: print 'Malformed time.' else: print 'time is fine.'
If I try to do a command such as:
elapsedTime = timeResult2 - timeResult
...it will tell me that - is an invalid operation on a string.
Is there any way that I can extract the individual %H and %M values from the original string?