Is it possible to get the atomic clock timestamp from the iphone GPS?

后端 未结 5 1348
一向
一向 2020-12-03 06:12

I\'m looking for a reliable way to get the time. It can\'t be tampered with and it needs to work offline. So no internet time , no user time setup in settings and no BSD u

5条回答
  •  生来不讨喜
    2020-12-03 06:51

    This gets you the current date and time:

    NSDate *now = [NSDate date];
    

    This will be as reliable as you can get. The internal clock on the iPhone will be updated when it can get access to an NTP server. If the phone uses GPS as a time sync source it'll also be used to update the same system-wide clock which is accessible via the above method.

    The CoreFoundation equivalent is something like:

    CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
    

    Which returns the CoreFoundation equivalent of the normal UNIX seconds-since-epoch timestamp.

提交回复
热议问题