Python Forum
Need to sum up HHMMS AM/PM DD/MM/YYYY and a HH:MM:SS.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need to sum up HHMMS AM/PM DD/MM/YYYY and a HH:MM:SS.
#3
If you are measuring your runtime in seconds it might make more sense using datetime.fromtimestamp()
from datetime import datetime

now = datetime.now().timestamp()
runtime = 1 * 3600 + 22 * 60 + 14  # 1:22:14 seconds

print(datetime.fromtimestamp(now))
print(datetime.fromtimestamp(now + runtime))
Output:
2023-01-04 14:52:30.891579 2023-01-04 16:14:44.891579
If your runtime is a HH:MM:SS string, Yoriz's solution is a better choice.
tester_V likes this post
Reply


Messages In This Thread
RE: Need to sum up HHMMS AM/PM DD/MM/YYYY and a HH:MM:SS. - by deanhystad - Jan-04-2023, 08:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  regex to extract only yy or yyyy metalray 2 3,636 Jul-11-2018, 07:57 PM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020