"13-11-2012 09:14:39" is the sample timestamp string getting from server in my app. I need to calculate the defference between that time and current device time.
My Server is sending the time in GMT format. Do i need to change the device timezone to GMT to calculate current time in GMT? And how can i get exact diff b/w those two times. Please help me.
Here is what i have tried so far:
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
Date requestDate = formatter.parse(serverDateString);
Calendar requestDateCal = formatter.getCalendar();
requestDateCal.setTime(requestDate);
Calendar currentDateCal = Calendar.getInstance();
calculateTimeDiff(currentDateCal.getTimeInMillis(), requestDateCal.getTimeInMillis()); //finds diff between two timestamps
TRy this,
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
Date requestDate = formatter.parse(serverDateString);
Calendar requestDateCal = formatter.getCalendar();
requestDateCal.setTime(requestDate);
Calendar currentDateCal = Calendar.getInstance();
currentDateCal.setTimeZone(TimeZone.getTimeZone("GMT"));
calculateTimeDiff(currentDateCal.getTimeInMillis(), requestDateCal.getTimeInMillis()); //finds diff between two timestamps