如何在应用程序中设置DatePicker对话框

时间:2019-06-18 12:00:21

标签: android

SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dd-MM-yyyy, hh:mm:ss, context. GetResources().getConfiguration().locale); 

simpleDateFormat.setTimeZone(TimeZone.getDefault());
return simpleDateFormat.format(new Date(myDate));

此代码仅在我保存便笺时显示日期,不允许我为活动选择日期

1 个答案:

答案 0 :(得分:1)

您可以通过以下方式显示Datepicker对话框

<input type="checkbox" className="custom-control-input"
                       checked={this.state.isChecked}
                       onChange={this.toggleChange}
/>

在OnClick方法中设置以下代码

// Global declaration
Calendar preferDate1 = new GregorianCalendar();
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
private int year, month, day;

并在MainClass中添加它

DatePickerDialog dp = new DatePickerDialog(MainActivity.this, preferredDate1Picker, preferDate1.get(Calendar.YEAR), preferDate1.get(Calendar.MONTH), preferDate1.get(Calendar.DAY_OF_MONTH));
dp.getDatePicker().setMinDate(c.getTimeInMillis());//Only if You want to set min date
dp.show();