Format of Date in Android in 15-Aug-47

Jyotishgher Astrology
By -
0

 

Format of Date in Android in 15-Aug-47

Suppose you have edit box and on click you want the format to capure like below format then use below Steps:Eg

14-Oct-22

txt_dobText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);


DatePickerDialog dialog = new DatePickerDialog(Login.this, android.R.style.Widget_Material, mDateSetListener, year, month, day);
//Getting Today date to calendar2
final Calendar calendar2 = Calendar.getInstance();
//Set Minimum date of calendar
calendar2.set(2020, 1, 1);
dialog.getDatePicker().setMinDate(calendar2.getTimeInMillis());

dialog.getDatePicker().setMaxDate(new Date().getTime());
// Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
});

mDateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {

int day = dayOfMonth;
int yy = year;
int month = ++monthOfYear;
String str_day = day < 10 ? "0" + day : "" + day;
String str_month = month < 10 ? "0" + month : "" + month;
if (str_month.equalsIgnoreCase("01")) {
str_month =
"JAN";
}
else if (str_month.equalsIgnoreCase("02")) {
str_month =
"FEB";
}
else if (str_month.equalsIgnoreCase("03")) {
str_month =
"MAR";
}
else if (str_month.equalsIgnoreCase("04")) {
str_month =
"APR";
}
else if (str_month.equalsIgnoreCase("05")) {
str_month =
"MAY";
}
else if (str_month.equalsIgnoreCase("06")) {
str_month =
"JUN";
}
else if (str_month.equalsIgnoreCase("07")) {
str_month =
"JUL";
}
else if (str_month.equalsIgnoreCase("08")) {
str_month =
"AUG";
}
else if (str_month.equalsIgnoreCase("09")) {
str_month =
"SEP";
}
else if (str_month.equalsIgnoreCase("10")) {
str_month =
"OCT";
}
else if (str_month.equalsIgnoreCase("11")) {
str_month =
"NOV";
}
else if (str_month.equalsIgnoreCase("12")) {
str_month =
"DEC";
}


String from_date_select = str_day + "-" + str_month + "-" + String.valueOf(yy).substring(2, 4);


txt_dobText.setText(from_date_select);

Log.d("FirstDoseDate=", "onDateSet: dd/mm/yyy: " + from_date_select);


}
};

Post a Comment

0Comments

Post a Comment (0)