Reputation: 721
I've got a "normal" DatePicker
that is made like this:
// funzioni del datepicker
protected DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
}
};
protected Dialog onCreateDialog(int id) {
return new DatePickerDialog(this.getParent(),mDateSetListener,mYear, mMonth, mDay);
}
and I call showDialog(0);
to expose this.
It works, but the date is in the yyyy-mm-dd
format. I need to change it in the dd-mm-yyyy
format.
Also, can i add the hour and minutes to this?
Upvotes: 0
Views: 429
Reputation: 3277
// Converting Date format from (YYYY_MM-DD) to (DD-MM-YYYY)
private String convertDate(String cdate)
{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat postFormater = new SimpleDateFormat("dd-MM-yyyy");
Date convertedDate;
convertedDate = dateFormat.parse(cdate);
cdate = postFormater.format(convertedDate);
return cdate;
}
Upvotes: 1