user2218449
user2218449

Reputation: 7

Change date text to date

I want to change my date text (7 Apr 2013) to date (2013-04-07) in eclipse android

My function now :

DateFormat fmtDate = DateFormat.getDateInstance();
Calendar date = Calendar.getInstance();
DatePickerDialog.OnDateSetListener d_start = new DatePickerDialog.OnDateSetListener() {
    public void onDateSet(DatePicker view, int year, int monthOfYear,
            int dayOfMonth) {
        date.set(Calendar.YEAR, year);
        date.set(Calendar.MONTH, monthOfYear);
        date.set(Calendar.DAY_OF_MONTH, dayOfMonth);
        updateLabel();
    }
}; 
private void updateLabel() {
    dateLabel.setText(fmtDate.format(date.getTime()));

}

How i can change format date like 2013-04-07? I don't have a many idea. Thank's

Upvotes: 2

Views: 109

Answers (2)

JustDanyul
JustDanyul

Reputation: 14044

You should use SimpleDateFormatter instead, so replace this line

DateFormat fmtDate = DateFormat.getDateInstance();

with

SimpleDateFormat fmtDate =
            new SimpleDateFormat("yyyy-MM-dd");

For more information, give this page a look

Upvotes: 2

Xavier Delamotte
Xavier Delamotte

Reputation: 3599

You simply need to replace your fmtDate by

DateFormat fmtDate = new SimpleDateFormat("yyyy-MM-dd")

Upvotes: 3

Related Questions