Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: smallpoul on December 21, 2023, 11:41:40 AM
-
Hi,
could someone point me out on how to convert millisecond to a time stamp so i could have hour minute and second. I tried some code but unable to achive my goald.
Thanks in advance.
Mike
-
This might be what you want or at least get you started.
--Converts decimal seconds to an HH:MM:SS.xx format
function SecondsToTime(seconds)
if seconds == 0 then
return "00:00:00"
else
local hours = string.format("%02.f", math.floor(seconds/3600))
local mins = string.format("%02.f", math.floor((seconds/60) - (hours*60)))
--local secs = string.format("%04.2f",(seconds - (hours*3600) - (mins*60)))
local secs = string.format("%02.0f",(seconds - (hours*3600) - (mins*60)))
return hours .. ":" .. mins .. ":" .. secs
end
end
-
Thanks it work perfectly.
-------------------------------------------------------
-- Machine up time
-------------------------------------------------------
local Milliseconds = mc.mcCntlGetPoundVar(inst, 3001 )
local seconds = string.format("%02.f", math.floor(Milliseconds/1000))
if seconds == 0 then
scr.SetProperty("Machineuptime", "Label", "00:00:00")
else
local hours = string.format("%02.f", math.floor(seconds/3600))
local mins = string.format("%02.f", math.floor((seconds/60) - (hours*60)))
local secs = string.format("%02.0f",(seconds - (hours*3600) - (mins*60)))
scr.SetProperty("Machineuptime", "Label", hours ..":" ..mins ..":".. secs)
end