3 Replies
      Latest reply on Nov 12, 2019 12:48 AM by eskimo
      Peter2131 Level 1 Level 1 (0 points)

        I trying to find device last reboot time and it should not affect if user go and change time and date from settings. I tried using sytem up and kernel boot time i am geting time when device was last rebooted but if go into setting n change +2/-2 hours with date boot time changes. Appreciate any suggestions. Thank you

        • Re: Identify device last reboot time
          eskimo Apple Staff Apple Staff (12,285 points)

          What I’d do in your situation is get the current current time, get the boot time (see this post), and diff them to get the up time [1].  Then subtract that up time from a timestamp you get from the network.  That will give you a similarly trusted timestamp for the boot time.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

          [1] The fact that the boot time changes when the system clock changes means that that this difference is always meaningful.

            • Re: Identify device last reboot time
              Peter2131 Level 1 Level 1 (0 points)

              Thank You Eskimo for your response

              question

              (1) Not sure i understand timestamp from network i dont get any time from server

              (2) For current time any suggestions? should i use timesince1970??

                • Re: Identify device last reboot time
                  eskimo Apple Staff Apple Staff (12,285 points)

                  Not sure i understand timestamp from network i dont get any time from server

                  I’m suggesting you use the network to contact a server you trust to get the time.  It’s not possible to trust any timestamp you get locally because, as you’ve noticed, the user can change the time.

                  For current time any suggestions? should i use timesince1970??

                  If I’m working at this layer of the system I generally use gettimeofday.  It works in the same units as kern.boottime.  Alternatively you can map the kern.boottime value to NSDate and work in NSDate space.  It doesn’t really matter.

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"