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

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

This code only showing me date when I save my note, it doesn't allow me to pick a date for my event

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30

1 Answers1

1

You can display Datepicker Dialog using below way

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

Set Below code in OnClick method

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

And Add this in MainClass

private final DatePickerDialog.OnDateSetListener preferredDate1Picker = new DatePickerDialog.OnDateSetListener() {

    @Override
    public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) {
        preferDate1 = new GregorianCalendar(selectedYear, selectedMonth, selectedDay);

        textview.setText((selectedDay < 10 ? "0" + String.valueOf(selectedDay) : String.valueOf(selectedDay)) + "/"
            + (selectedMonth + 1 < 10 ? "0" + String.valueOf((selectedMonth + 1)) : String.valueOf((selectedMonth + 1)))
            + "/" + selectedYear);

    }
};
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Chirag Savsani
  • 6,020
  • 4
  • 38
  • 74