Skip to content

Instantly share code, notes, and snippets.

@rnemeth90
Created May 25, 2023 18:13
Show Gist options
  • Save rnemeth90/b67178b8fbcfe02f5783306e6d85a37d to your computer and use it in GitHub Desktop.
Save rnemeth90/b67178b8fbcfe02f5783306e6d85a37d to your computer and use it in GitHub Desktop.
Calculate Diff of Two Time Strings in Python
from datetime import datetime
start_time = "10:44:09.339931"
end_time = "10:44:09.376233"
t1 = datetime.strptime(start_time, "%H:%M:%S.%f")
print('Start time:', t1.time())
t2 = datetime.strptime(end_time, "%H:%M:%S.%f")
print('End time:', t2.time())
delta = t2 - t1
ms = delta.total_seconds() * 1000
print(f"Time difference is {ms} milliseconds")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment