Hello Guest it is April 28, 2024, 06:41:29 AM

Author Topic: Convert millisecond to time  (Read 454 times)

0 Members and 1 Guest are viewing this topic.

Convert millisecond to time
« 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

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Convert millisecond to time
« Reply #1 on: December 21, 2023, 05:54:17 PM »
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
Re: Convert millisecond to time
« Reply #2 on: December 22, 2023, 10:29:29 AM »
Thanks it work perfectly.
Code: [Select]
-------------------------------------------------------
--  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