Created
May 25, 2023 18:13
-
-
Save rnemeth90/b67178b8fbcfe02f5783306e6d85a37d to your computer and use it in GitHub Desktop.
Calculate Diff of Two Time Strings in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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