Wenn Benutzer wählen date
zwischen von und date
. wie zu calculate
anzahl der nacht in 3rd Edittext
in android? für datepicker
meinen Code NachSo berechnen Sie die Anzahl der Tage zwischen zwei Datepicker in Android
3 edittext box
1 Von Datum 2 bis Datum 3 Anzahl der Nacht =?
CheckInDate = (EditText) rootView.findViewById(R.id.CheckInDate);
CheckOutDate = (EditText) rootView.findViewById(R.id.CheckOutDate);
CheckInDate.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
if (v == CheckInDate) {
final Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
c.set(Calendar.DAY_OF_MONTH, mDay);
DatePickerDialog dpd = new DatePickerDialog(getActivity(),
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, monthOfYear);
cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
cal.set(Calendar.YEAR, year);
if(cal.before(c)) {
Toast.makeText(getActivity(), "Select valid date please.", Toast.LENGTH_LONG).show();
return;
}
StringBuilder date = new StringBuilder();
date.delete(0, date.length());
date.append((dayOfMonth<10?"0":"")).append(dayOfMonth)
.append("/").append((monthOfYear + 1) < 10 ? "0" : "")
.append((monthOfYear+1)).append("/").append(year);
CheckInDate.setText(date.toString());
}
}, mYear, mMonth, mDay);
dpd.getDatePicker().setMinDate(c.getTimeInMillis());
dpd.show();
}
}
});
CheckOutDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v == CheckOutDate) {
final Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
c.set(Calendar.DAY_OF_MONTH, mDay);
DatePickerDialog dpd = new DatePickerDialog(getActivity(),
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, monthOfYear);
cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
cal.set(Calendar.YEAR, year);
if(cal.before(c)) {
Toast.makeText(getActivity(), "Select valid date please.", Toast.LENGTH_LONG).show();
return;
}
StringBuilder date = new StringBuilder();
date.delete(0, date.length());
date.append((dayOfMonth<10?"0":"")).append(dayOfMonth)
.append("/").append((monthOfYear + 1) < 10 ? "0" : "")
.append((monthOfYear+1)).append("/").append(year);
CheckOutDate.setText(date.toString());
}
}, mYear, mMonth, mDay);
dpd.getDatePicker().setMinDate(c.getTimeInMillis());
dpd.show(); }
}
});
Sie Joda Zeit verwenden können: http://stackoverflow.com/questions/3802893/number-of-days-between-two-dates-in-joda- Zeit – antonio