|
|||||||
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
||||
|
||||
|
Simply insert this function into your project then call it as you would any normal function, example below:
Code:
function sec2Min(secs)
if secs > 59 then
myMinutes = Math.Floor(secs/60);
mySeconds = secs-(Math.Floor(secs/60)*60);
if mySeconds < 10 then
mySeconds = "0"..mySeconds;
end
myTime = myMinutes..":"..mySeconds;
else
if secs < 10 then
mySeconds = "0"..secs;
end
myTime = "0:"..mySeconds;
end
return myTime;
end
Code:
result = sec2Min(75);
Dialog.Message("Time:", result);
|
|
#2
|
||||
|
||||
|
You can also use the string.format function which is part of lua to zero fill a variable.
mySeconds = string.format("%2f", secs-(Math.Floor(secs/60)*60);t); tigg
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
|
#3
|
||||
|
||||
|
Quote:
Right on 'Tigg! |
|
#4
|
||||
|
||||
|
Yep. To quote the late great Ed Whalen from Stampede Wrestling, "That's a ring-a-ding-dong dandy".
|
|
#5
|
|||
|
|||
|
ditto , tks Tigg
(and for yours Mr Corey) |
|
#6
|
||||
|
||||
|
I didn't test the code above but here is a funciton that will convert seconds to HH:MM:SS.
Code:
function SecondsToClock(sSeconds)
local nSeconds = String.ToNumber(sSeconds)
if nSeconds == 0 then
--return nil;
return "00:00:00";
else
nHours = string.format("%02.f", Math.Floor(nSeconds/3600));
nMins = string.format("%02.f", Math.Floor(nSeconds/60 - (nHours*60)));
nSecs = string.format("%02.f", Math.Floor(nSeconds - nHours*3600 - nMins *60));
return nHours..":"..nMins..":"..nSecs
end
end
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
|
#7
|
||||
|
||||
|
Seconds to Hours Minutes Seconds - Convert - Conversion
Quote:
|
|
#8
|
|||
|
|||
|
#9
|
||||
|
||||
|
Ah, ha Ah, ha ha.
Thanks Worminator, "not just a Terminator, but a Worminator sort of Terminator!" "Stamping out problematic code chunks in a single leap!"
|
|
#10
|
|||
|
|||
|
I have a need to get a number in milliseconds and convert it to 'HH:MM:SS.t' where 't' is rounded to tenths of a second.
Can this function be used to do that? |
|
#11
|
||||
|
||||
|
should be able to. Just need to adjust the math so it calculates from miliseconds rather than seconds
Code:
function MilliSecondsToClock(sMilliSeconds)
local nMilliSeconds = String.ToNumber(sMilliSeconds)
if nMilliSeconds == 0 then
--return nil;
return "00:00:00";
else
nHours = string.format("%02.f", Math.Floor(nMilliSeconds/3600000));
nMins = string.format("%02.f", Math.Floor(nMilliSeconds/60000 - (nHours*60000)));
nSecs = string.format("%02.f", Math.Floor(nMilliSeconds/1000 - nHours*3600000 - nMins *60000));
nMilliSecs = Math.Round(nMilliseconds - (nHours*3600000) - (nMins *60000) - (nSecs *1000))
return nHours..":"..nMins..":"..nSecs.."."..nMilliSecs
end
end
HTH Tigg
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Another tough one... Interaction between Web and AMS | Agent Jones | AutoPlay Media Studio 5.0 | 13 | 08-18-2005 03:10 PM |
| Function: Convert boolean value to string | Desmond | AutoPlay Media Studio 5.0 Examples | 0 | 05-07-2004 02:14 PM |
All times are GMT -6. The time now is 09:51 PM.









Linear Mode

