Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to create an uptime command for the bot e.g "the bot has been online for 10 hours 15 minutes 10 seconds"

It works the way as indented up until it hits 12am, I think it might be to do with the calculation but I'm unsure on why it would add -1day when its formatted in hours minutes seconds.

This is what I have at the moment. Any help would be appreciated :)

from datetime import datetime
import os
import time

folder = r"C:UsersRyan MclaughlinPycharmProjectsSnappingbot-V2SnappingbotV2ext files"
filename = "uptime.txt"
fp = os.path.join(folder, filename)

with open(fp, "w") as f:
    f.writelines(datetime.now().time().strftime('%H:%M:%S')) # on startup of bot write the time in a file
file = open(fp)

startup_time = (file.readline())  # reads the startup time

print(startup_time)
time.sleep(10)
time_now = datetime.now().time().strftime('%H:%M:%S')  # finds time now
print(time_now)

FMT = '%H:%M:%S'
tdelta = datetime.strptime(time_now, FMT) - datetime.strptime(startup_time,FMT)  # calculates the difference between the startup time and now
print(tdelta)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
124 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...