How to get the date and time from the network provider?

Is there a way to get time and time from a network provider programmatically? Perhaps in the same way that we get a location from a network provider.

+10
android datetime time
Aug 23 2018-11-11T00:
source share
3 answers

You may need to use the custom NITZ or NTP library.

So, it’s just the head that Android uses the NITZ events provided by the carrier to correctly set the system’s date and time. Android also crashes to network NTP automatically when there is no cellular network.

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

The time provided by currentTimeMillis () will usually be the best time available, and this is what all services on the device use, like a calendar and an alarm clock.

However

However, the NTP API is not the one that Java code can access, which means that we are back to using the existing Java NTP / SNTP client library if we want accurate time, regardless of whether we are on the network for NITZ.

Java NTP Library

You can find the naive implementation of the Java NTP library from

+4
Aug 23 2018-11-11T00:
source share

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

@Override public void onLocationChanged(Location loc) { loc.getLatitude(); loc.getLongitude(); latitude.setText(""+loc.getLatitude()); longitude.setText(""+loc.getLongitude()); time.setText(""+loc.getTime()); } 
0
Sep 08 2018-11-11T00:
source share

There is already a better answer to this question, but in case someone needs an easier way, here's what I did.

Get server time using an API or network call in which the response will have a timestamp from the server. Use the data according to your convenience.

You can modify the existing API, if any.

0
May 16 '19 at 6:24
source share



All Articles