1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| public void GetDateTime() { final Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE);
DatePickerDialog picker = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int year, int month, int day) { String date = year + "-" + (month + 1) + "-" + day; Log.i(TAG, "DATE:" + date); TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener(){ @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { String t = String.format(" %02d:%02d", hourOfDay, minute); Log.i("TimePickerFragment", "onTimeSet: " + t); } }, hour, minute, DateFormat.is24HourFormat(getActivity())); timePickerDialog.show(); } }, year, month, day);
picker.show();
}
|