dimanche 19 avril 2015

How to convert datepicker format to dd-MM-yyyy

In database table I use a date format which inserts date like 04-04-2015. Then using a datePicker through variable 'from_date' I choose the same date and that date is like 4-4-2015. If I want to select rows using the date selected from datepicker I get no rows even though rows are available. How to change the datePicker date to 04-04-2015 from 4-4-2015 or how to insert the date like 4-4-2015 instead of 04-04-2015.



private DatePickerDialog.OnDateSetListener myDateListener
= new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
dateView.setText(new StringBuilder()
// Month is 0 based so add 1
.append(arg3).append("-") //day
.append(arg2+1).append("-")//month
.append(arg1).append(" "));//year
from_date=dateView.getText().toString();
startActivity(new Intent( datefrom.this, dateto.class));
}
};

Code for insertion:
contentvalues.put(VivzHelper.TX_DATE,new SimpleDateFormat
("dd-MM-yyyy").format(new Date()));

Aucun commentaire:

Enregistrer un commentaire