Re: Second-Time conversion
Re: Second-Time conversion
- Subject: Re: Second-Time conversion
- From: Graff <email@hidden>
- Date: Thu, 24 Jun 2004 00:21:30 -0400
On Jun 23, 2004, at 11:04 PM, John Mistler wrote:
Given say, 188 seconds, is there a simple way to convert the number to
either "00:03:08" or "03:08"?
There are many ways to do this. Here are two of them:
This first way uses the date class that is part of AppleScript. This
should work just fine but might have problems if your locale has a odd
way of displaying the time:
----
on TimeToString(theTime)
set aDate to current date
set (time of aDate) to theTime
return text 4 thru -4 of time string of aDate
end
----
The second way uses good old math and should work fine as long as you
don't feed it something odd like a negative amount of seconds:
----
on TimeToString(theTime)
set theSec to theTime mod 60
set theMin to (theTime mod 3600) div 60
set theHour to theTime div 3600
set timeString to PadNum(theHour)
set timeString to timeString & ":"
set timeString to timeString & PadNum(theMin)
set timeString to timeString & ":"
set timeString to timeString & PadNum(theSec)
return timeString
end TimeToString
on PadNum(theNum)
if (theNum < 10) then
return "0" & theNum
else
return "" & theNum
end if
end PadNum
----
- Ken
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.