Seba500PLK Posted January 24, 2015 Share Posted January 24, 2015 Hello, my problem is that such shows. 02:60:59. Minutes and days shows correctly. Hour is displayed wrong. function math.round(number, decimals, method) decimals = decimals or 0 local factor = 10 ^ decimals if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor else return tonumber(("%."..decimals.."f"):format(number)) end end function formatTimeFromMinutes(value) if value then local weekday = math.floor(value / 1440) local hours = math.floor(value / 60) local minutes = math.round((value / 60 - math.floor(value / 60)) * 100 / 1.6666666666666667) if weekday < 10 then weekday = "0" .. weekday end if hours < 10 then hours = "0" .. hours end if minutes < 10 then minutes = "0" .. minutes end value = weekday.. ":" ..hours .. ":" .. minutes return value end return false end function displaytime() local alivetime = getElementData(getLocalPlayer(), "alivetime") outputChatBox(formatTimeFromMinutes(alivetime)) end ElementData "alivetime" +1 is added every 1 minute Link to comment
.:HyPeX:. Posted January 24, 2015 Share Posted January 24, 2015 I'm not sure what you're doing, but check how i make min:seg:ms time = tostring(time) ms = tostring(math.round(tonumber((time/1000 - ("%02d"):format(time/1000))*1000))) min = (((time-ms)/1000)/(60)) diff = (min - math.floor(min))*60 ms = ("%03d"):format(tostring(math.round(ms))) min = ("%02d"):format(tostring(math.round(min))) sec = ("%02d"):format(tostring(math.round(diff))) Link to comment
Seba500PLK Posted January 24, 2015 Author Share Posted January 24, 2015 0.oI mean that when this will occur 24 hours a feed added one day, and that mattered again Link to comment
.:HyPeX:. Posted January 24, 2015 Share Posted January 24, 2015 Have fun scripting, and read my explanation! function formatTimeFromMinutes(value) if value then local weekday = math.floor(value / 1440) local value = value - ( math.floor(weekday) * 1440 ) local hours = math.floor(value/24) local value = value - ( math.floor(hours) * 24 ) local minutes = math.floor( value ) weekday = ("%02"):format(tostring(math.round(weekday))) hours = ("%02"):format(tostring(math.round(hours))) minutes = ("%02"):format(tostring(math.round(minutes))) value = weekday.. ":" ..hours .. ":" .. minutes return value end return false end --[[ MATH EXPLANATION Eg time: 1764 weekday = 1764 / 1440 = 1.225 math.floor(weekday) = 1 value = value - weekday(1) * 1440 -> Remove correctly value = 324 hours = 324 / 24 = 13.5 math.floor(hours) = 13 value = value - hours(13) * 24 -> Remove correctly value = 324 - 312 = 12 minutes = value --> Remaining is minutes Result = 1 Day : 13 Hours : 12 minutes ]] 1 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