I tried myself and found an error, getting the time in milliseconds for the Current Time calendar instance.
You got an error because the time in milisecond for CurrentTime was not accurate , it was somehow an error, but it was 1 month less than the current time , so why did you get the answer in the local.
You can do this below.
Calendar calCurr = Calendar.getInstance(); Log.i("Time in mili of Current - Normal", ""+calCurr.getTimeInMillis()); // see what it gives? dont know why? Date date = new Date(); calCurr.set(date.getYear()+1900, date.getMonth()+1, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());// so added one month to it Log.i("Time in mili of Current - after update", ""+calCurr.getTimeInMillis()); // now get correct Calendar start = Calendar.getInstance(); start.set(2012, 12, 1, 11, 28, 0); Calendar end = Calendar.getInstance(); end.set(2012, 12, 1, 13, 28, 0); if((start.compareTo(calCurr)==-1) && (calCurr.compareTo(end)==-1) && (start.compareTo(end)==-1)) { double hrBetweenStartEnd = (end.getTimeInMillis()-start.getTimeInMillis())/3600000; double hrBetweenStartCurr = (calCurr.getTimeInMillis()-start.getTimeInMillis())/3600000; int percentage = (int) ((100*hrBetweenStartCurr)/hrBetweenStartEnd); Log.i("Percentage", ""+percentage); }
source share