1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question Time format

Discussion in 'Android Questions' started by Beja, Jun 23, 2019.

  1. Beja

    Beja Expert Licensed 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?
     
  2. emexes

    emexes Well-Known Member 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:
    Code:
    SecondOfMinute = (DateTime.Now / 1000Mod 60
     
    Beja likes this.
  3. Beja

    Beja Expert Licensed User

    Thanks emexes.
    Will try that out.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice