I am making a potion type system and when I have more than 24 hours, it displays wrong, how do I make it display days??
My current code:
os.date("!%X", info.Start + info.Time - os.time())
I am making a potion type system and when I have more than 24 hours, it displays wrong, how do I make it display days??
My current code:
os.date("!%X", info.Start + info.Time - os.time())
From my testing, %X
does return the remaining hours, minutes and seconds exclusive of the days. So, the idea would be to just calculate the number of days and append it to the string in the format: dd:hh:mm:ss
:
local remaining_time = info.Start + info.Time - os.time()
local formatted_time = os.date("!%X", remaining_time)
-- finding number of days: "remaining_time" is in seconds and there are 86400 seconds in one day
local days = math.floor(remaining_time / 86400)
formatted_time = ("%02d:%s"):format(days, formatted_time)
print(formatted_time)