Jump to content

Convert seconds to MM:SS:MI


DooMAGE
 Share

Recommended Posts

Hello guys!

 

I am working on a hud stopwatch timer thing for my game, but looks like I can't use os.date("%X",0) from Lua since I guess you can't upload games with sandbox Lua off to the game launcher :/

 

Having a little trouble to format my Time:GetSpeed()/100 to something like MM:SS:MI

 

Thanks in advance smile.png

  • Thanks 1

My Leadwerks games!

https://ragingmages.itch.io/

Link to comment
Share on other sites

Hello guys!

 

I am working on a hud stopwatch timer thing for my game, but looks like I can't use os.date("%X",0) from Lua since I guess you can't upload games with sandbox Lua off to the game launcher :/

 

Having a little trouble to format my Time:GetSpeed()/100 to something like MM:SS:MI

 

Thanks in advance smile.png

 

Time:GetCurrent() is in MS. I'd do it something like below. StartTime would need to be initialized to whatever time the timer starts with Time:GetCurrent()

 

local MS = Time:GetCurrent() - StartTime

local Minutes = math.floor(MS  / 60000)
MS = MS - Minutes * 60000

local Seconds = math.floor(MS / 1000)
MS = MS - Seconds * 1000

local TimeStamp = Minutes..":"..Seconds..":"..MS

  • Upvote 1
Link to comment
Share on other sites

Thanks thehankinator, now I can show the timer on the screen :)

But I am having a hard time to reset the stopwatch.

 

Tried force MS = 0 using a If, but when the if is no more true the timer resumes and keeps going up.

 

Maybe I need some beer :P

Beer helps but to to reset the timer just reinitialize StartTime with Time:GetCurrent()

  • Upvote 1
Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...