I am trying to show a date in android with the selected year, month and day using DatePicker. I have problems with choosing the year, month and day and displaying them on the screen in the correct format for the phone locale without displaying the time.
At the moment, the code will correctly display the date, but also displays the time.
StringBuilder string = new StringBuilder()
.append(mYear).append("-")
.append(mMonth + 1).append("-")
.append(mDay);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date = format.parse(string.toString());
mDateDisplay.setText(date.toLocaleString());
} catch (ParseException e) {
e.printStackTrace();
}
mDateDisplay is a TextView.
I cannot figure out how to get rid of the time, which is also displayed. I made a lot of documents for searching and reading, and I could not figure it out. Any help would be appreciated.
source
share