Possible Duplicate:
How to convert Milliseconds to “X mins, x seconds” in Java?
Calculating the Difference Between Two Java Date Instances
I have a function like this:
public String setDateAndTime(int h, int m, int s,int amPm) {
TimeZone nst = TimeZone.getTimeZone("GMT+5:45");
Calendar calendar1 = new GregorianCalendar(nst);
Date currentTime1 = new Date();
calendar1.setTime(currentTime1);
calendar1.set(Calendar.HOUR, h);
calendar1.set(Calendar.MINUTE, m);
calendar1.set(Calendar.SECOND, s);
calendar1.set(Calendar.YEAR, calendar1.get(Calendar.YEAR));
calendar1.set(Calendar.MONTH, calendar1.get(Calendar.MONTH));
calendar1.set(Calendar.DAY_OF_MONTH, calendar1.get(Calendar.DAY_OF_MONTH));
calendar1.set(Calendar.AM_PM, amPm);
DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
String date = formatter.format(calendar1.getTime());
return date;
}
Through this function i created two dates(String)
String s1=setDateAndTime(12,00,00,1);//12:00:00 PM
String s2=setDateAndTime(3,15,45,0);//3:15:45 AM
Now how to find to find difference between s1 and s2, i also need the hours, minutes and second lefts, so that i can do further processing.