I am using this coded to generate date picker in android.
DatePickerDialog datePicker = new DatePickerDialog(this, datePickerListener, y, m, d);
datePicker.getDatePicker().setMaxDate(System.currentTimeMillis());
Right now max
date is current date. I want to set it as 14 years ago. How can I do that?
If you like to restrict access of users to select a date within a range then there is minDate and maxDate options are available in jQuery UI. Using this you can set the date range of the Datepicker. After defining these options the other days will be disabled which are not in a defined range.
Android provides controls for the user to pick a time or pick a date as ready-to-use dialogs. Each picker provides controls for selecting each part of the time (hour, minute, AM/PM) or date (month, day, year).
Android DatePicker is a user interface control that is used to select the date by day, month, and year in the android application. DatePicker is used to ensure that the users will select a valid date.
You can do this by using Calender
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, -14);
DatePickerDialog datePicker = new DatePickerDialog(this, datePickerListener, y, m, d);
datePicker.getDatePicker().setMaxDate(calendar.getTimeInMillis());
One approach would be by using JodaTime:
datePicker.getDatePicker().setMaxDate(new DateTime().minusYears(14));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With