Setting time and date to date picker and time picker in android

andro-girl picture andro-girl · Apr 28, 2011 · Viewed 84k times · Source

I am using a date picker and time picker in my application. I want to set the date and time when the page loads. Is this possible? How so?

Answer

yildirimyigit picture yildirimyigit · Dec 9, 2011

I solved a similar problem of mine as follows

Calendar cal = Calendar.getInstance();

int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int min = cal.get(Calendar.MINUTE);

datePicker.updateDate(year, month, day);

timePicker.setCurrentHour(hour);
timePicker.setCurrentMinute(min);