Leo Long

unread,
Aug 6, 2016, 1:37:18 AM8/6/16
to MIT App Inventor Forum
Hello,

I want to calculate the remaining time between now and the future set time.

For example:
-I want to have a 5 minutes break. 
-The time now is 1pm and I set the timepicker to 13 05.

Then, I enabled the timer to count down and show the duration in seconds to a label. But it gives me negative numbers(e.g "-1470436642")
So how do I fix it?

Thanks,
Leo
blocks.png

Taifun

unread,
Aug 6, 2016, 10:15:17 AM8/6/16
to MIT App Inventor Forum
the clock.now method gives you an instant in date and time
the timepicker,instant gives you only an instant in time (date is 1.1.1970 in this case)
you can see this using Do it

which means, one solution is to add the current date to the time picker instant...
Taifun

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


Leo Long

unread,
Aug 6, 2016, 7:24:03 PM8/6/16
to MIT App Inventor Forum
-First solution:
If I add the current date to the time picker instant, it still gives me negative numbers.

-Second solution:
So I modified a bit and this gives me what I wanted but the seconds doesn't seem to count down.
The label should be updating every minute, but it is stuck although the notifier notify me once the duration reach 0.

Could you explain to me the first solution? I couldn't make it work. 
Also, if my second solution works fine?(although it works)

Thanks,
Leo
newblocks.png

Taifun

unread,
Aug 7, 2016, 1:26:23 PM8/7/16
to MIT App Inventor Forum
you did not add the current date to the time picker intent...
it's a little bit more complicated, see screenshot
and we also have to consider the time difference from UTC to the current timezone (im in UTC -6 so I would have to add 6 hours in the example), the timezone difference we also can get this from the clock component...


probably someone comes up with an easier solution?

but to make it simpler, why not only selecting the number of minutes for the countdown?

Taifun
Reply all
Reply to author
Forward
0 new messages