我怎样才能得到日期&网络提供商的时间? [英] How can I get the date & time from the network provider?

查看:22
本文介绍了我怎样才能得到日期&网络提供商的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获得日期&以编程方式从网络提供商处获取时间?可能与我们从网络提供商处获取位置的方式相同.

Is there a way to get the date & time from the network provider programmatically? Possibly in the same manner in which we get the location from the network provider.

推荐答案

您可能需要使用自定义 NITZ 或 NTP 库

所以请注意,Android 使用运营商提供的 NITZ 事件正确设置系统日期和时间.Android 也回退到当没有可用的蜂窝网络时自动网络 NTP.

So just a heads up that Android uses NITZ events provided by a carrier to properly set the system date and time. Android also falls-back to network NTP automatically when no cellular network is available.

http://en.wikipedia.org/wiki/NITZ

currentTimeMillis() 提供的时间通常是最好的可用时间,这是设备上所有服务使用的时间,比如日历和闹钟.

The time provided by currentTimeMillis() will typically be the best available time, and it's what all of the services on the device use, like Calendar and Alarm Clock.

不过

然而,NTP API 不是 Java 代码可以访问的地方,这意味着我们将重新使用现有的 Java NTP/SNTP 客户端库,如果无论我们是否在网络上,我们都需要准确的时间这是 NITZ 能力.

However the NTP API isn't somewhere that Java code can access, which means we're back to using an existing Java NTP/SNTP client library if we want an accurate time regardless of whether we are on a network that is NITZ capable.

Java NTP 库

你可以从

这篇关于我怎样才能得到日期&网络提供商的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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