seconds to standard time numberformat?
Cubist at aol.com
Cubist at aol.com
Fri Aug 22 12:52:00 EDT 2003
sez mdswindell at charter.net:
>Is there a numberformat or other option that will display seconds in
>standard 00:00:00 format?
The CONVERT function is your friend for all things related to display of
time and/or dates. To a first approximation:
function Sec2Standard DaSecs
convert DaSecs from seconds to long time
return DaSecs
end Sec2Standard
This will give you results like "10:53:12 PM" -- that is, you'll get the
hour, minute, second *and* whether it's AM or PM. Of course, your original
question didn't mention the AM/PM bit at all; since the "long time" time format
automatically includes the AM/PM bit, we must needs find a different way to do
it if we don't want to deal with AM/PM. Fortunately, the dateItems time/date
format gives you everything you need on a silver platter, or at least in a
comma-delimited list whose individual parts you can access thru "item X of
TheTime". To a second approximation:
function Sec2Standard DaSecs
convert DaSecs from seconds to dateItems
return item 4 of DaSecs & ":" & item 5 of DaSecs & ":" & item 6 of DaSecs
end Sec2Standard
No AM/PM here, thanks. However, it's worth noting that dateItems believes
in a 24-hour clock; if you send this function the number of seconds
corresponding to "10:53:12 PM", it will spit out the result "22:53:12". Could this be a
problem for what you're doing? I dunno, but fortunately, it's not difficult to
translate a 24-hour *hour* into a 12-hour *hour*, you should pardon the
expression. To a third approximation:
function Sec2Standard DaSecs
convert DaSecs from seconds to dateItems
# mind the line wrap here...
return ((((item 4 of DaSecs) - 1) mod 12) + 1) & ":" & item 5 of DaSecs &
":" & item 6 of DaSecs
end Sec2Standard
There: Whether the number of seconds you send this puppy corresponds to
"10:53:12 PM" or "10:53:12", this function *will* give "10:53:12" right back to
you.
Hope this helps...
More information about the use-livecode
mailing list