Indigo Rose Software

Go Back   Indigo Rose Software Forums > AutoPlay Media Studio 7.5 > AutoPlay Media Studio 7.5 Examples

Reply
 
Thread Tools Display Modes
  #1  
Old 01-18-2006
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
Post Function: Convert seconds into minutes/seconds formatted for display, i.e. "2:30"

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
Example call to convert 75 seconds into formatted "m:s" time:

Code:
result = sec2Min(75);
Dialog.Message("Time:", result);
Reply With Quote
  #2  
Old 01-20-2006
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
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
Reply With Quote
  #3  
Old 01-20-2006
Intrigued's Avatar
Intrigued Intrigued is offline
Indigo Rose Customer
 
Join Date: Dec 2003
Location: Location! Location!
Posts: 6,058
Quote:
Originally Posted by TJ_Tigger
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
I'm going to use this instead of my code I have been using.

Right on 'Tigg!
__________________
Intrigued
www.amsuser.com
Reply With Quote
  #4  
Old 01-20-2006
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
Yep. To quote the late great Ed Whalen from Stampede Wrestling, "That's a ring-a-ding-dong dandy".
Reply With Quote
  #5  
Old 01-21-2006
Eagle Eagle is offline
Indigo Rose Customer
 
Join Date: Mar 2005
Location: WA 'wait a while' - Australia
Posts: 827
ditto , tks Tigg

(and for yours Mr Corey)
Reply With Quote
  #6  
Old 01-26-2006
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
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
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
Reply With Quote
  #7  
Old 08-22-2006
Intrigued's Avatar
Intrigued Intrigued is offline
Indigo Rose Customer
 
Join Date: Dec 2003
Location: Location! Location!
Posts: 6,058
Seconds to Hours Minutes Seconds - Convert - Conversion

Quote:
Originally Posted by TJ_Tigger
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
Tigg
Thanks 'Tig, little late maybe, but it saves me from coding such.
__________________
Intrigued
www.amsuser.com
Reply With Quote
  #8  
Old 08-22-2006
Worm Worm is offline
Indigo Rose Customer
 
Join Date: Jul 2002
Location: USA
Posts: 3,937
don't forget DateDiff does this too

http://www.indigorose.com/forums/sho...13&postcount=7
Reply With Quote
  #9  
Old 08-22-2006
Intrigued's Avatar
Intrigued Intrigued is offline
Indigo Rose Customer
 
Join Date: Dec 2003
Location: Location! Location!
Posts: 6,058
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!"

__________________
Intrigued
www.amsuser.com
Reply With Quote
  #10  
Old 11-24-2006
Tek Tek is offline
Forum Member
 
Join Date: Mar 2004
Location: Toronto, ON CANADA
Posts: 691
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?
Reply With Quote
  #11  
Old 11-24-2006
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
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
Or something close to that anyway.

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


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.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software