#How format seconds into minutes

97 messages · Page 1 of 1 (latest)

latent geyser
#

Title

#

like, 600 seconds into 10:00

vagrant slate
#
seconds - totaltime - math.floor(totaltime/60) * 60

#

format the string after that and that's it

latent geyser
#

yay

#

i hope that works

#

causei cant check rn

#

but

#

ty

weary niche
cosmic forge
#
print(os.date("%H:%M:%S", 160))
#

this also works

#

nvm not really as reliable

latent geyser
#

lol

cosmic forge
#

for some reason it starts like a couple hours before the epoch

#
print(os.date("%M:%S", 600 + 5* 60 * 60))
--  14:16:13.492  > print(os.date("%M:%S", 600 + 5* 60 * 60  ))  -  Studio
--  14:16:13.492  10:00  -  Edit
#

this will work tho

#

it was just 5 hours behind the epoch

raven maple
#

;compile

local seconds = 600

print(string.format("%d:%02d", math.floor(seconds / 60), seconds % 60))
misty pelicanBOT
#
Program Output
10:00

raven maple
#

@latent geyser

#

@cosmic forge

#

💪

cosmic forge
#

("%02i"):format(seconds/60)

#

auto floor 😎

latent geyser
#

are u guys still arguing about this?

raven maple
#

Nobody's arguing?

latent geyser
#

same thing

raven maple
#

No, it's not 👁️👄👁️

latent geyser
#

shuddup

raven maple
#

Luau auto-floors all number directives

#

@cosmic forge

#

Lua doesn't, however

latent geyser
cosmic forge
#

lol

latent geyser
#

i mean its not too bad if i just remove the Hours

cosmic forge
#

you need to add 5*60*60

#

cause its 5 hours behind

latent geyser
#

why

#

atleast it works

cosmic forge
#

cause its epoch time technically which is the seconds from Jan 1st 12 AM 1970

latent geyser
#

1970!?

#

whats epoch time!?

cosmic forge
#

i just told u

#

its the number of seconds

#

from the epoch

#

which is january 1st 12 am 1970

latent geyser
#

whats the epoch :v

cosmic forge
#

the epoch is a specific time and date

#

the most common is

#

the time i just told you

#

it was chosen by unix developers during unix's development because its convinient to work with

#

unix was released in 1971

raven maple
#

Use my solution, @latent geyser

#

;compile

local seconds = 70 -- 1:10

for secondsLeft = seconds, 0, -1 do
    print(string.format("%d:%02d", math.floor(secondsLeft / 60), secondsLeft % 60)) 
    -- The result of this format-string should be assigned to your TextLabel

    -- task.wait(1)
end
misty pelicanBOT
#
Program Output
1:10
1:09
1:08
1:07
1:06
1:05
1:04
1:03
1:02
1:01
1:00
0:59
0:58
0:57
0:56
0:55
0:54
0:53
0:52
0:51
0:50
0:49
0:48
0:47
0:46
0:45
0:44
0:43
0:42
0:41
0:40
0:39
0:38
0:37
0:36
0:35
0:34
0:33
0:32
0:31
0:30
0:29
0:28
0:27
0:26
0:25
0:24
0:23
0:22
0:21

raven maple
#

Simple and intuitive, no overhead

cosmic forge
#

i agree use his solution

#

;compile

local seconds = 70 -- 1:10

for secondsLeft = seconds, 0, -1 do
    print(string.format("%d:%02d", secondsLeft / 60, secondsLeft % 60)) 
    -- The result of this format-string should be assigned to your TextLabel

    -- task.wait(1)
end
misty pelicanBOT
#
Program Output
/opt/wandbox/lua-5.4.3/bin/lua: prog.lua:4: bad argument #2 to 'format' (number has no integer representation)
stack traceback:
[C]: in function 'string.format'
prog.lua:4: in main chunk
[C]: in ?

raven maple
cosmic forge
#

oh

#

thats what you meant

raven maple
#

Yeah. You can use "%d" or "%i" in Luau and it wouldn't make a difference. In Lua, both fail to floor the input value

#

The closest you can get to cross-compatible code is through math.floor

#

(Seething that Roblox hasn't introduced //)

cosmic forge
#
local seconds = 70 -- 1:10

for secondsLeft = seconds, 0, -1 do
    print(string.format("%02d:%02d", secondsLeft / 60, secondsLeft % 60)) 
    -- The result of this format-string should be assigned to your TextLabel

    -- task.wait(1)
end
cosmic forge
raven maple
#

For future updates?

cosmic forge
#

yeah

#

found it

raven maple
#

I did too; looking at it now

misty pelicanBOT
#
Program Output
/opt/wandbox/lua-5.4.3/bin/lua: prog.lua:4: bad argument #2 to 'format' (number has no integer representation)
stack traceback:
[C]: in function 'string.format'
prog.lua:4: in main chunk
[C]: in ?

misty pelicanBOT
#
Program Output
1:10
1:09
1:08
1:07
1:06
1:05
1:04
1:03
1:02
1:01
1:00
0:59
0:58
0:57
0:56
0:55
0:54
0:53
0:52
0:51
0:50
0:49
0:48
0:47
0:46
0:45
0:44
0:43
0:42
0:41
0:40
0:39
0:38
0:37
0:36
0:35
0:34
0:33
0:32
0:31
0:30
0:29
0:28
0:27
0:26
0:25
0:24
0:23
0:22
0:21

raven maple
#

Looks like it's already been implemented. Finally.

raven maple
latent geyser
#
    for i = IntermissionLength, 0, -1 do
        if i == 0 then
            print("Game starting")
            else
            end
            
        else
            wait(0.2) 
            AnnounceE:FireAllClients(os.date("%M:%S", i + 5* 60 * 60))
        end
    end
misty pelicanBOT
#
Program Output
/opt/wandbox/lua-5.4.3/bin/lua: prog.lua:7: 'end' expected (to close 'for' at line 1) near 'else'

latent geyser
#

woops

#
    for i = IntermissionLength, 0, -1 do
        if i == 0 then
            print("Game starting")
            if #game.Players:GetPlayers() >= 1 then
                RS.GameEvents.GameStart:Fire()
            else
                AnnounceE:FireAllClients("Waiting for players...")
            end
            
        else
            wait(0.2) 
            AnnounceE:FireAllClients(os.date("%M:%S", i + 5* 60 * 60))
        end
    ```
misty pelicanBOT
#
Program Output
/opt/wandbox/lua-5.4.3/bin/lua: prog.lua:13: 'end' expected (to close 'for' at line 1) near <eof>

latent geyser
#

man i give up

#

it works tho

raven maple
#

Seriously, you're using an overcomplicated solution that does more work than is needed, @latent geyser

#

Anyone who looks at that code will be confused, lol

latent geyser
#

it still works

raven maple
#

That is the single-most stupid mentality one could have when it comes to coding

latent geyser
#

but it works