多的我是真不爱说 上代码咯
//获取一个日历的对象
cal = Calendar.getInstance();
//获取年月分 时分秒的信息
year = cal.get(Calendar.YEAR);
month = cal.get(Calendar.MONTH)+1;
//当月的多少天
day = cal.get(Calendar.DAY_OF_MONTH);
hour = cal.get(Calendar.HOUR_OF_DAY);
minute = cal.get(Calendar.MINUTE);
setTitle(year+"-"+month+"-"+day+" "+hour+":"+minute);
//date picker初始化
datePicker.init(year, month-1, day, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
setTitle(year+"-"+(monthOfYear+1)+"-"+dayOfMonth);
}
});
timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
setTitle(hourOfDay+":"+minute);
}
});
new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
setTitle(year+"-"+(monthOfYear+1)+"-"+dayOfMonth);
}
},year,cal.get(Calendar.MONTH),day).show();
new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
setTitle(hourOfDay+":"+minute);
}
},hour,minute,true).show();