-1

I got one time from the server. This time saved in a array and I show this time in TextView with this code in adapter:

txttime.setText(time[position]);

I have current time with System.currentTimeMillis() and I want to calculate Different between System.currentTimeMillis() and my time that got from server. I want to use this result in CountDownTimer()

new CountDownTimer(result, 1000)

Thanks for your advice :)

Sunil P
  • 3,698
  • 3
  • 13
  • 20
mohammad
  • 33
  • 1
  • 1
  • 7

1 Answers1

1

Try this. Think that time1 is your current time and time2 is server time which you are getting.

String Time1 = "10/02/14 09:29:50";
        String Time2 = "11/04/14 09:12:43";

            // date format
            SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss");  

        Date d1 = null;
        Date d2 = null;
        try {
            d1 = format.parse(Time1);
            d2 = format.parse(Time2);
        } catch (ParseException e) {
            e.printStackTrace();
        }    


        long diff = d2.getTime() - d1.getTime();
        long diffSeconds = diff / 1000;         
        long diffMinutes = diff / (60 * 1000);         
        long diffHours = diff / (60 * 60 * 1000);                      
        System.out.println("Time in seconds: " + diffSeconds + " seconds.");         
        System.out.println("Time in minutes: " + diffMinutes + " minutes.");         
        System.out.println("Time in hours: " + diffHours + " hours."); 
Sunil P
  • 3,698
  • 3
  • 13
  • 20