Skip to content Skip to sidebar Skip to footer

How To Get Time From Server In Android?

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

Solution 1:

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

LocationManagerlocMan= (LocationManager) activity.getSystemService(activity.LOCATION_SERVICE);
longtime= 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

Solution 2:

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 = newSimpleDateFormat(format,
            Locale.US);
    String data = sdf.format(newDate(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 = newString(b);

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

cya, Bertan

Post a Comment for "How To Get Time From Server In Android?"