Skip to first unread message

Ergin

unread,
Feb 12, 2017, 8:18:44 PM2/12/17
to MIT App Inventor Forum
hi guys,

I need to get time difference by minute, hour, day and month between two dates. How can I do that ?
First date is first openining date of app and second date is current date. Just I want to know how long time passed from first opening my app.

Rudolph Karstadt

unread,
Feb 13, 2017, 8:44:39 AM2/13/17
to MIT App Inventor Forum
hello

you can use the clock. In the designer mode add the clock (sensors) to your design. There are a lot of fuctions to calculate with date and time.

First you have to save  the time when the App starts.
then you can use the difference to the current time to display the elapsed time.

another way to show the time


there ist also DurationToDays and DurationToWeek

you can try all these functions


greetings
Rudolph

Abraham Getzler

unread,
Feb 13, 2017, 12:03:01 PM2/13/17
to MIT App Inventor Forum
 Just I want to know how long time passed from first opening my app.

You have to use TinyDB to remember the first opening instant of your app.

Screen1.Initialize

If Get_TinyDB1(tag="firstInstantMillis", default=0) = 0 then
  SaveTinyDB1( (tag="firstInstantMillis", value=Clock1.GetMillis(Clock1.Now()))

The GetMillis clock block converts an Instant into the number of milliseconds from 1970 to that Instant.
Subtracting the GetMillis of two Instants gives you the milliseconds between those Instants.
All the rest is math.
Search this board for Countdown apps for conversion from milliseconds to days, hours, etc.

ABG


Ergin

unread,
Feb 17, 2017, 3:04:42 AM2/17/17
to mitappinv...@googlegroups.com

Ergin

unread,
Feb 17, 2017, 3:10:11 AM2/17/17
to MIT App Inventor Forum
I also attach aia file herewith in case of anyone else need same project.
timer.aia

Abraham Getzler

unread,
Feb 17, 2017, 10:03:02 AM2/17/17
to MIT App Inventor Forum
Very Nice!

This is the first example I've seen that does all the work of separating out the day, hours, minutes, and seconds in one JOIN.

Added to the Clock section of this FAQ:

ABG

Reply all
Reply to author
Forward
0 new messages