Does anyone know how to change the date format in DatePickerDialog in Android studio in Java, I need like "Mon, May 6" I need like this format instead of "M05 6, Mon"Image link .
agetxt.setOnClickListener(v -> {
Utils.HideKeyboard(FarmInputs.this);
DatePickerDialog datePicker = new DatePickerDialog(FarmInputs.this, 0, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
Date = dayOfMonth + "/" + (month + 1) + "/" + year;
DateDb = year + "-" + (month + 1) + "-" + dayOfMonth;
agetxt.setText(Date);
try {
Age = GetDays(dayOfMonth + "/" + (month + 1) + "/" + year);
} catch (ParseException e) {
e.printStackTrace();
}
}
}, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
datePicker.setCancelable(false);
datePicker.getDatePicker().setMaxDate(System.currentTimeMillis() + Constants.days60_millisecond);
datePicker.show();
3
Answers
To change the date format in DatePickerDialog in Android Studio to something like "Mon, May 6", you can format the date using SimpleDateFormat after selecting the date. Here’s how you can do it:
Import the necessary classes:
Update your onDateSet method to format the date:
In this example:
We use Calendar to set the selected date.
SimpleDateFormat is used to format the date as "Mon, May 6".
The formatted date is set to the agetxt TextView.
This approach ensures the date is displayed in the desired format after the user selects a date.
Use below code to achieve your output, And set it with your requirements
Output
Code
Try This Way.