How can I get the date & time from the network provider?

前端 未结 2 874
情话喂你
情话喂你 2020-12-03 11:59

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.

相关标签:
2条回答
  • 2020-12-03 12:38

    You may need to use a custom NITZ or NTP Library

    • http://groups.google.com/group/android-developers/browse_thread/thread/d5ce3bcfe17e272b?pli=1

    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

    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.

    However

    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 library

    You can find a naive implementation of a Java NTP Library from

    • support.ntp.org
    0 讨论(0)
  • 2020-12-03 13:00

    The Answer is YES I tried the following code to get the time from network provider use loc.getTime() for that

        @Override
        public void onLocationChanged(Location loc)
        {
            loc.getLatitude();
            loc.getLongitude();
    
            latitude.setText(""+loc.getLatitude());
            longitude.setText(""+loc.getLongitude());
            time.setText(""+loc.getTime());
        }
    
    0 讨论(0)
提交回复
热议问题