python - Print Difference Between Time in Ms -


i reading log file in python script, , have got list of tuples of starttimes , endtimes -

('[19:49:40:680]', '[19:49:49:128]') ('[11:29:10:837]', '[11:29:15:698]') ('[11:30:18:291]', '[11:30:21:025]') ('[11:37:44:293]', '[11:38:02:008]') ('[11:39:14:897]', '[11:39:21:572]') ('[11:42:19:968]', '[11:42:22:036]') ('[11:43:18:887]', '[11:43:19:633]') ('[11:44:26:533]', '[11:49:29:274]') ('[11:55:03:974]', '[11:55:06:372]') ('[11:56:14:096]', '[11:56:14:493]') ('[11:57:08:372]', '[11:57:08:767]') ('[11:59:26:201]', '[11:59:27:438]') 

how can take difference of times in milliseconds?

>>> import datetime >>> = ('[19:49:40:680]', '[19:49:49:128]') >>> start = datetime.datetime.strptime(a[0][:-1]+"000", "[%h:%m:%s:%f") >>> end = datetime.datetime.strptime(a[1][:-1]+"000", "[%h:%m:%s:%f") >>> delta = end-start >>> ms = delta.seconds*1000 + delta.microseconds/1000 >>> ms 8448.0 

this works if clock wraps around @ midnight:

>>> = ('[23:59:59:000]','[00:00:01:000]') >>> # <snip> see above >>> ms = delta.seconds*1000 + delta.microseconds/1000 >>> ms 2000.0 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -