Jump to content

Convert seconds left into minutes left


The Silvas

Recommended Posts

Hi,

 

I can get the number of seconds left from my timer using: ztimerClock.Remaining

 

However, this just returns the seconds. I want to convert that into easier to read time. Something like:

 

You have 3:23 left.

 

Can anyone help with how to do this?

 

Thanks

Link to comment

min = (seconds - sec) / 60

 

Hi, thanks for the quick reply, however something is not quite right.

 

You said (seconds - sec) / 60 and because seconds is not a variable it gives an error.

 

I tried min = ztimerClock.Remaining / 60 however this gives a number with a lot of decimal points.

 

Thanking you in advance.

Link to comment

local sec, min
sec = ztimerClock.Remaining % 60
min = (ztimerClock.Remaining - sec) / 60
Wherigo.MessageBox{Text="You have " .. min .. ":" .. sec .. " left."}

And that's what I get for rewriting code before I post it. I originally had it defined as a function where seconds was a parameter, then I rewrote part of it and didn't notice I still had that variable inside.

 

Anyway, after each line, here are the values:

sec = 0, min = 0, ztimerClock.Remaining = 203

sec = 23, min = 0, ztimerClock.Remaining = 203

sec = 23, min = 3, ztimerClock.Remaining = 203

"You have 3:23 left."

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...