如果设备日期和时间不准确,我如何获得实际的日期和时间? [英] How can I get the actual date and time if the device date and time are inaccurate?

查看:458
本文介绍了如果设备日期和时间不准确,我如何获得实际的日期和时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到如果我手动设置我的设备时间,并关闭iOS设备上的自动时间同步, [NSDate date] 会返回假设的日期和时间设备时间是正确的 - 它可能不是。

I noticed that if I set my device time manually, and turn off the automatic time sync on my iOS device, [NSDate date] returns the date and time assuming the device time is correct--which it may not be.

由于文档提到 NSDate 有某种与NTP同步,我想知道是否有任何内置方法来获得准确的日期和时间,而不必假设设备的日期和时间是正确的。

Since the docs mention that NSDate has some sort of sync with NTP, I am wondering if there is any built-in way to get the accurate date and time instead of having to assume the device date and time is correct.

推荐答案

也许 https://github.com/jbenet/ios-ntp 可以帮到你吗?它是一个可以从时间服务器获取日期和时间的库。

Perhaps https://github.com/jbenet/ios-ntp can help you? It's a library that can fetch the date and time from a time server.

这篇关于如果设备日期和时间不准确,我如何获得实际的日期和时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆