Android TimePicker Set 24 Hours
TimePicker
is a view for selecting the time of day, in either 24 hour or AM/PM mode.
You can use setIs24HourView(true)
method with TimePicker.
Android Code
timePicker = (TimePicker) findViewById(R.id.timePicker1);
timePicker.setIs24HourView(true);
timePicker.setCurrentHour(Calendar.get(Calendar.HOUR_OF_DAY));
Difference between Starting Date and Ending Date Use jodatime API
Days.daysBetween(start.toDateMidnight() , end.toDateMidnight() ).getDays()
where 'start' and 'end' are your DateTime objects. To parse your date Strings into DateTime objects use the parseDateTime method
If you not Use jodatimeAPI do something following way,
Calendar thatDay = Calendar.getInstance();
thatDay.set(Calendar.DAY_OF_MONTH,25);
thatDay.set(Calendar.MONTH,7); // 0-11 so 1 less
thatDay.set(Calendar.YEAR, 1985);
Calendar today = Calendar.getInstance();
long diff = today.getTimeInMillis() - thatDay.getTimeInMillis(); //result in millis
long days = diff / (24 * 60 * 60 * 1000); // approximation
If you parse date from string. you could use
String strThatDay = "1990/06/20";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
Date d = null;
try {
d = formatter.parse(strThatDay);
} catch (ParseException e) {
System.err.println("Error: " + e.getMessage());
}
Calendar thatDay = Calendar.getInstance();
thatDay.setTime(d); //rest is the same....