0

I have been struggling with this for a while.

Is there a method to ALWAYS display the date format in YYYY/MM/DD in a DatePicker widget regardless of user specific locales?

I have been searching the web for the whole day but I can only find how to get the date/time and convert it to other formats but not how to actually get the cursed widget to display a different time format.

The only related answer that I can find on stackoverflow is this. Surely there has to be an easier way than to brute force the API.

To clarify my context and usage: I'm using my DatePicker in a Fragment(NOT DialogFragment extending a DatePickerDialog).

Community
  • 1
  • 1
sebster
  • 1,322
  • 2
  • 18
  • 29

1 Answers1

0
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
    int dayOfMonth) {

int month = monthOfYear + 1;
String formattedMonth = "" + month;
String formattedDayOfMonth = "" + dayOfMonth;

if(month < 10){

    formattedMonth = "0" + month;
}
if(dayOfMonth < 10){

    formattedDayOfMonth = "0" + dayOfMonth;
}
searchText.setText(formattedDayOfMonth + "/" + formattedMonth + "/" + year);

}

stackoverflow
  • 2,320
  • 3
  • 17
  • 21