Blue Eye Macro
http://blueeye-macro.com/

Code: Convert milliseconds to hh:mm:ss
http://blueeye-macro.com/viewtopic.php?f=123&t=34966
Page 1 of 1

Author:  stakemaster [ Fri Nov 01, 2019 11:59 pm ]
Post subject:  Code: Convert milliseconds to hh:mm:ss

Example code to convert milliseconds, as returned by a stopwatch, to zero-filled hh:mm:ss.
Code:
 begin
     // convert milliseconds to hh:mm:ss (whole seconds)
     Variable.Set("runtime", "20000000")
     Function.Execute("convert ms to hhmmss")
 end

function("convert ms to hhmmss")
     begin
          Variable.Copy("runtime", "ms")
          Variable.Divide (Math)("ms", "1000")
          Variable.Floor (Math)("ms")
          Variable.Copy("ms", "s")
          Variable.To modulo (Math)("s", "60")
          Variable.Copy("ms", "m")
          Variable.Divide (Math)("m", "60")
          Variable.Floor (Math)("m")
          Variable.Copy("m", "h")
          Variable.To modulo (Math)("m", "60")
          Variable.Divide (Math)("h", "60")
          Variable.Floor (Math)("h")
          Function.Execute setting 3 variables("ZeroFillTime","strHour", "{h}", "strMinutes", "{m}", "strSeconds", "{s}")
          Window.Display message box("{strFormattedTime}", "yes")
     end
function

function("ZeroFillTime")
     begin
          if  Variable.Is less than (Math)("strHour", "10")
               begin
                    Variable.Evaluate (Text)("0{strHour}", "strHour")
               end
          if  Variable.Is less than (Math)("strMinutes", "10")
               begin
                    Variable.Evaluate (Text)("0{strMinutes}", "strMinutes")
               end
          if  Variable.Is less than (Math)("strSeconds", "10")
               begin
                    Variable.Evaluate (Text)("0{strSeconds}", "strSeconds")
               end
          Variable.Evaluate (Text)("{strHour}:{strMinutes}:{strSeconds}", "strFormattedTime")
     end
function

Author:  Syrifina [ Sat Nov 02, 2019 5:55 am ]
Post subject:  Re: Code: Convert milliseconds to hh:mm:ss

very cool!

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/