Jump to content

Format string to "00:00"


AMARANT

Recommended Posts

Posted

Hi there. I need to format my string (actually it is a number) to time formatted string, e.g. "300" to "05:00", "16" to "00:16", etc. Please help me.

Posted

Try to use

string.format("%02d:%02d",.......,...........) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

  • MTA Team
Posted

The read-ability might be better, but performance-wise it's crap.

Here is the code:

local seconds = 330 
local time = ("%02d:%02d"):format(math.floor(seconds / 60), seconds % 60) 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...