Jump to content

Seconds to minutes


drk

Recommended Posts

Posted (edited)

I used getTimePassed() to get the time of the player, it returns miliseconds, then I converted to seconds, and how to convert to minutes?

Example: I get 2.456 seconds semttulowju.png

Then I want to convert 2.456 seconds to --:-- minutes ( -- is the time )

Edited by Guest
Posted
function convertTime(ms) 
    local min = math.floor ( ms/60000 ) 
    local sec = math.floor( (ms/1000)%60 ) 
    return min, sec 
end 

You can use it like this:

local minutes, seconds = convertTime(60000) 

Posted

I tried:

                local time = msToSeconds( exports.race:getTimePassed( ) ) 
                local converted = convertTime(time) 

msToSeconds:

    function msToSeconds( int ) 
        if type( int ) == 'number' then 
            return int/1000 
        end 
        return false 
    end 

But it return 0 minutes.

Posted

Look, my function converts milliseconds to: minutes, seconds.

Just use it like I show you above.

local milliseconds = exports.race:getTimePassed( ) 
local mins, secs = convertTime(milliseconds) 

Posted
function convertTime(ms) 
    local min = math.floor ( ms/60000 ) 
    local sec = math.floor( (ms/1000)%60 ) 
    return min, sec 
end 

local minutes, seconds = convertTime(60000) 

Use this

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...