I have a requirement like calculating remaining days between two-dates. It is working fine for me. but the problem is when i sent the build to UK, there it is displaying one day less compare to India(ex: India :215 days but in UK:214 days). I am using the below code:
public static int noOfDays(String currDate, String tarDate){
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date1 = null;
Date date2 = null;
try {
date1 = sdf.parse(currDate);
date2 = sdf.parse(tarDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (int)( (date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24));
}
For getting current date:
public static String getcurrentdate()
{
Calendar now = Calendar.getInstance();
int month = now.get(Calendar.MONTH) + 1;
int year = now.get(Calendar.YEAR);
int day = now.get(Calendar.DATE);
return day+"/"+month+"/"+year;
}
And i believe that Calendar now = Calendar.getInstance(); will gives the Local time Zone instance only.if it is right then it should give same result in any location.but the result seems different. Please help me to resolve this issue.
Thanks, Ganesh