0

We are writing an application in android. We are taking server date and time. But sometimes we are getting blank response from server so my android application crashes due to blank. I have handled it in my code. But User can not see server time. I don't want to deal with local device time. Sometimes that cannot be correct.We want date and time from server all time. How can I avoid such unpredictable behavior of API. Suggest another API to get date and time for India server.

Here is sample code which I am using.

        String TIME_SERVER = "time-a.nist.gov";   
        NTPUDPClient timeClient = new NTPUDPClient();
        InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);           

        TimeInfo timeInfo = timeClient.getTime(inetAddress);

        long returnTime = timeInfo.getMessage().getTransmitTimeStamp().getTime();

        serverDate = new Date(returnTime);
        System.out.println("Time from " + TIME_SERVER + ": " + serverDate);

        SimpleDateFormat formatter1 = new SimpleDateFormat("dd-MM-yyyy");

        Log.e("FORMATED DATE", ""+formatter1.format(serverDate));

Is there any other alternate option to get server date and time ( for ISD )?

Prashant
  • 1,351
  • 3
  • 20
  • 32

0 Answers0