使用DatePicker
片段是這樣的:
private static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// Copy the Date to the EditText set.
dateValue = String.format("%04d", year) + "-" + String.format("%02d", monthOfYear + 1) + "-" + String.format("%02d", dayOfMonth);
}
}
這應該是更容易獲得在首位的日期。使用以下代碼日期範圍:
public static List<Date> dateInterval(Date initial, Date final) {
List<Date> dates = new ArrayList<Date>();
Calendar calendar = Calendar.getInstance();
calendar.setTime(initial);
while (calendar.getTime().before(final)) {
Date result = calendar.getTime();
dates.add(result);
calendar.add(Calendar.DATE, 1);
}
return dates;
}
乾杯!
學分:this
一個簡單的搜索給了我這個:http://stackoverflow.com/questions/12083053/how-to-get-a-list-of-dates-between-two-dates-in -java-how-to-include-exclude-st – zeroke