Android Question Time format

Beja

Expert
Licensed User
Longtime User
Hello all
For a purpose I want to act on change in seconds from 00 to 59 .. Hours and minutes are ignored. This means
11:12:16 equals 10:35:16
Any idea?
 

emexes

Expert
Licensed User
DateTime.GetSeconds should do the trick.

I was going to say: watch out for changes at the start and end of daylight savings... but you should be ok because I believe all adjustments are a whole number of minutes (usually one hour).

Depending on your application, you might have to watch out for the leap second that happens every few years. Although leap seconds are added, not skipped, and thus the worst that might happen is that you launch your rockets (or whatever it is you're doing) twice instead of once.

You could calculate it from DateTime.Now, by dividing by 1000 (convert ms to s) and then modulus 60 (to "wrap it around" within 0..59), eg:
B4X:
SecondOfMinute = (DateTime.Now / 1000) Mod 60
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
DateTime.GetSeconds should do the trick.

I was going to say: watch out for changes at the start and end of daylight savings... but you should be ok because I believe all adjustments are a whole number of minutes (usually one hour).

Depending on your application, you might have to watch out for the leap second that happens every few years. Although leap seconds are added, not skipped, and thus the worst that might happen is that you launch your rockets (or whatever it is you're doing) twice instead of once.

You could calculate it from DateTime.Now, by dividing by 1000 (convert ms to s) and then modulus 60 (to "wrap it around" within 0..59), eg:
B4X:
SecondOfMinute = (DateTime.Now / 1000) Mod 60

Thanks emexes.
Will try that out.
 
Upvote 0
Top