2

我想在 Eclipse android 中将我的日期文本(2013 年 4 月 7 日)更改为日期(2013-04-07)

我现在的功能:

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()));

}

我如何更改格式日期,如 2013-04-07?我没有太多的想法。谢谢

4

2 回答 2

3

你只需要替换你fmtDate

DateFormat fmtDate = new SimpleDateFormat("yyyy-MM-dd")
于 2013-04-07T00:11:05.503 回答
2

您应该改用 SimpleDateFormatter,所以替换这一行

DateFormat fmtDate = DateFormat.getDateInstance();

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

有关更多信息,请查看此页面

于 2013-04-07T00:12:33.917 回答