Maurize Posted September 6, 2012 Share Posted September 6, 2012 Hej Lets pretend I got a number like 2000(seconds) I want the number be like: hh:mm:ss Anyone an idea? Link to comment
Tete omar Posted September 6, 2012 Share Posted September 6, 2012 What exactly do you think 60 sec = 1 min that means 2000 sec = 33 minutes divide 60 ÷ 2000 anyway hh:mm:ss 00:33:333333333333333333333333333333 Link to comment
Maurize Posted September 6, 2012 Author Share Posted September 6, 2012 Yeah thats how i want it... But is there a function or something... Im not good in math Link to comment
Tete omar Posted September 6, 2012 Share Posted September 6, 2012 Yeah thats how i want it... But is there a function or something...Im not good in math Function about what ? Link to comment
Controls Posted September 6, 2012 Share Posted September 6, 2012 HejLets pretend I got a number like 2000(seconds) I want the number be like: hh:mm:ss Anyone an idea? https://community.multitheftauto.com/ind ... ls&id=4784 Link to comment
Anderl Posted September 6, 2012 Share Posted September 6, 2012 (edited) I'm not very good at maths and not very familiar with string.format but this should work: function msToStr( ms ) if( ms ) then return string.format( '%02d:%02d:%02d', ( tonumber( ms ) / ( 1000 * 60 * 60 ) ) % 60, ( tonumber( ms ) / ( 1000 * 60 ) ) % 60, ( tonumber( ms ) / 1000 ) % 60 ); end return false; end Example: msToStr( 2000 ); Edited September 7, 2012 by Guest Link to comment
TAPL Posted September 6, 2012 Share Posted September 6, 2012 not working lol msToStr( 2000 ) result: 2:2:202 1 Link to comment
Castillo Posted September 6, 2012 Share Posted September 6, 2012 function convertTime ( ms ) if ( ms and type ( ms ) == "number" ) then local mins = math.floor ( ms / 60000 ) local hours = math.floor ( mins / 60 ) local secs = math.floor ( ( ms / 1000 ) % 60 ) return string.format ( "%s:%s:%s", hours, ( mins - hours * 60 ), secs ) end end Link to comment
Maurize Posted September 6, 2012 Author Share Posted September 6, 2012 Again Solidsnake saved world of course the others did as well:) thanks! Link to comment
Callum Posted September 7, 2012 Share Posted September 7, 2012 You can use getRealTime. "timestamp" returns the UNIX timestamp, and you can use getRealTime(timestamp) to get the details of the timestamp (seconds, minutes, hours, days, months, years, etc). Link to comment
Anderl Posted September 7, 2012 Share Posted September 7, 2012 not working lol msToStr( 2000 ) result: 2:2:202 My bad, I wrote '%d02' instead of '%02d'. I tested it with this correction, it works perfectly. print( msToStr( 2000 ) ); --Output: 00:00:02 Link to comment
Maurize Posted September 8, 2012 Author Share Posted September 8, 2012 anderl i took yours, is the shortest and best:) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now