Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Finding elapsed time in minutes

$
0
0
Hello, I am trying to find the elapsed time between two times that are in a specific format. They are in HHMM format.

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?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>