Reputation: 7
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
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
Reputation: 3599
You simply need to replace your fmtDate
by
DateFormat fmtDate = new SimpleDateFormat("yyyy-MM-dd")
Upvotes: 3