Issue with clock duration

Hello,
I do a simple test:
I click on the initTemp button to copy the system time

When I click on LAP, I want to have the difference between the current time and the saved time.

I don’t understand why App Inventor systematically puts 1 hour when it’s good for minutes and seconds?

For example I have 01:01:02
instead of 00:01:02

when I have well 62 s elapsed ???


Despite my readings, I cannot clarify this point … if you have an idea?

thank you in advance
Ced

in which timezone are you located? GMT + 1?
you might want to try the Now method rather than the SystemTime method...
Taifun


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

Thank you for your reply. I am French.

I changed to “now” and I still have the same problem.

Are you using an emulator, or
are you using a device?

works fine for me here in Costa Rica, which is GMT -6
Unbenannt

EDIT: the Duration method returns a duration in milliseconds. The problem occurs after using the FormatDateTime method together with that duration, because that method expects an instant and not a duration.

Taifun


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

here is a working example without using the FormatDateTime block
Taifun
PS: I do not know, if the timezone issue is a bug or not?

lap.aia (3.6 KB)

Thank you for this proposal but it does not work for me (the proposed file) I still have this problem of 01:00:00 with the companion or APK ?? !!!
I tried to switch my tablet to GMT -6 and there I have 06:00:00

GMT 0 = 01:00:00
GMT +2: 02:00:00

Ced

as proof, that it does not work for you, what about providing a screenshot of your relevant blocks including Do it results?
see also tip 4 here App Inventor: How to Learn | Pura Vida Apps

Taifun

Hello,
I got the wrong archive in my previous answer, disregard it.

For the example proposed, it is complicated to display the result of the blocks because as it is local variables, the do it does not work … (or I do it wrong).

In any case when I click on btn lap:

I have the duration in milliseconds displayed.

By cons for the time above (label 1) I have results H: M: S like 00:13:99
00:14:72 but actually the 01 o’clock has given way to 00!
Ced

you can temporarily replace the local variables by global variables for easier debugging

it seems to be, you have to fix it then... you can do it!
Taifun

Taifun’s advice is correct, you need to convert with quotients and not use any clock conversion blocks.

Just to demonstrate what is happening here, when you seek to convert a millisecond value generated by calculating the difference between two dates, then seek to format it using clock blocks, this will convert the smaller millisecond value to an instant. A few seconds only will be starting from the beginning of the epoch (unix time) 01/01/1970. This instant has a ZONE_OFFSET of 3600000 which adds the hour to the formatted time.

A screenshot and some blocks:

Hello and thank you for your information.
I offer you in solution a block that I found which helped me to finally understand this operation. (convert Milli to seconds befor ! or change init local Sec to sec*1000)
blocks (19)
blocks (20)
As a bonus, a block to convert to KM / H … if it helps people.

Have a good day
Ced

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.