我如何获得日期&网络提供商提供的时间? [英] How can I get the date & time from the network provider?

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

问题描述

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

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天全站免登陆