Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to convert seconds to days, hours, minutes and seconds?

So im making a countdown to a day and i want to convert my seconds to days, hours, minutes and seconds.

My code

local TARGET_TIME = 1591525920

while wait(1) do
    if os.time() >= TARGET_TIME then
        start()
        break
    end

    local seconds = TARGET_TIME - os.time()
 -- here is where i want to convert the seconds variable into days, hours, mins and secs
end 

1 comment

0

ummm your going to respond to my answer?

1 answer

you would use math..

like this

local TARGET_TIME = 1591525920

local SECOND = 1;
local MINUTE = SECOND * 60;
local HOUR = MINUTE * 60
local DAY = HOUR * 24


local seconds = (((TARGET_TIME % DAY) % HOUR) % MINUTE) / SECOND;
local minutes = (((TARGET_TIME % DAY) % HOUR) - seconds) / MINUTE
local hours = ((TARGET_TIME % DAY) - (minutes + seconds)) / HOUR
local days = (TARGET_TIME - (minutes + seconds + hours)) / DAY

print("Time left:".. days .. ":" ..hours .. ":" ..minutes .. ":" .. seconds)

2 comments

0

Sorry for the late reply, i will try that in a minute

0

No, doesnt work

This discussion is preserved as it was. New answers, comments, and votes are closed.