2

Possible Duplicate:
Does anyone know of a good JSON time server?

Is there any public json or xml present on server which I can parse for current time? I shall use this time for checking the expiration Period of Trial version of my app, I am not using Calendar or Date classes. I am new in Android. Thanks.

Community
  • 1
  • 1
Kalu Khan Luhar
  • 1,044
  • 1
  • 22
  • 35

2 Answers2

5

I know its not exactly what you ask but you may also get the time from the network provider (the mobile phone network).

Have you tried

LocationManager locMan = (LocationManager) activity.getSystemService(activity.LOCATION_SERVICE);
long time = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getTime();

it returns the time in millis.

So you don't need an internet connection or parsing JSON, XML ...

Hope this helps somehow,

Tobias

Tobias Reich
  • 4,952
  • 3
  • 47
  • 90
0

I have a Utilities Web Service, that when I "ask" by SOAP to the Server, they return to me the Date.

@WebMethod(operationName = "getDateTime")
public byte[] getDateTime() {
    UtilWS.showIpClient(wsContext);

    String format = "yyyy-MM-dd HH:mm:ss.SSS";
    SimpleDateFormat sdf = new SimpleDateFormat(format,
            Locale.US);
    String data = sdf.format(new Date(System.currentTimeMillis()));

    System.out.println("== Date Requisiton: " + data);
    return data.getBytes();
}

And in my Client side:

byte[] b = CommWS.send(getApplicationContext(), "UtilWS", "getDateTime");
String server_date = new String(b);

The CommWS is my class that implements the SOAP communication with the Server.

cya,
Bertan

William Da Silva
  • 703
  • 8
  • 19