Converting milliseconds to hh:mm:ss

770 views
Skip to first unread message

J G

unread,
Feb 24, 2014, 9:46:37 PM2/24/14
to mitappinv...@googlegroups.com
So I'm building a bigger app that requires the use of a periodic timer that has to be displayed to the user. I have been able to get my desired times to spit out in milliseconds, but unable to display them nicely in an hh:mm:ss second format with leading zeroes. Is there an elegant way to do this or must I code an entire sequence (i.e. convert milliseconds to seconds, display seconds with leading zeroes using segment, when seconds = 60, add 1 to minute and reduce seconds to 0)? If so, how do I reference this entire procedure without having to re-make it multiple times (because there will be a few different timers within the program).

Taifun

unread,
Feb 25, 2014, 8:37:52 AM2/25/14
to mitappinv...@googlegroups.com
use a procedure with result http://appinventor.mit.edu/explore/ai2/support/blocks/procedures.html#return
input parameter is your time in milliseconds
output is your  time in an hh:mm:ss second format with leading zeroes.
and inside the procedure put your logic
Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

J G

unread,
Feb 25, 2014, 11:31:55 PM2/25/14
to mitappinv...@googlegroups.com



\\


Okay, that much makes sense. I'm having difficulty now with working the procedure. What I am trying to do below is:

1) Take the value of TotalTimeElapsed and spit it into the procedure "Calculate Seconds." That procedure for now will format the seconds between 0 and 60 (obviously later I have to add minutes and hours later). Then that calculation is spit out and displayed in TotalTimeDisp.

Calling the procedure, however, doesn't do anything. It's just spitting out the same as TotalTimeElapsed (i.e. making no changes).

What am I doing wrong?

Taifun

unread,
Feb 26, 2014, 9:14:31 AM2/26/14
to mitappinv...@googlegroups.com
your blocks look strange...
I recommend you to take a look here to get an idea hwo to work with the clock https://sites.google.com/site/blocks123/theclock
this is AI1, but the blocks are the same in AI2
Taifun

Reply all
Reply to author
Forward
0 new messages