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

后端 未结 5 1588
谎友^
谎友^ 2020-12-17 07:49

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?

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 08:12

    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);
    

提交回复
热议问题