-5
I’m wanting to add a zero in the day and month in the date that the editData_devolucao
receive. Like, instead of appearing day 05
is just 5
and in the month instead of appearing 06
appears only 6
.
Example:
- How do you return:
2/6/2021
- How I wanted you to return:
02/06/2021
The line that corresponds to the formatting of my date is
String data_dev = dia + "/" + mes + "/" + ano; // Formatação da data atual
Code
EditText editData_devolucao;
editData_devolucao = findViewById(R.id.editData_devolucao);
Calendar calendar = Calendar.getInstance(getDefault(Category.FORMAT));
dia = calendar.get(Calendar.DAY_OF_MONTH);
mes = calendar.get(Calendar.MONTH);
ano = calendar.get(Calendar.YEAR);
editData_devolucao.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
final DatePickerDialog datePickerDialog = new DatePickerDialog(
CadastrarEmprestimo.this, new DatePickerDialog.OnDateSetListener(){
@Override
public void onDateSet(DatePicker view, int ano, int mes, int dia){
mes += 1;
String data_dev = dia + "/" + mes + "/" + ano; // Formatação da data atual
editData_devolucao.setText(data_dev);
}
},ano,mes,dia);
datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis());
datePickerDialog.show();
}
});
This answers your question? Formatting date in java - just adapt the format to your case
– hkotsubo