Android - 格式日期为"日,月dd,yyyy"

Chr*_*tis 6 java android date-format

我从用户那里得到了他在DatePickerDialog中设置的日期.我得到的日期是这种格式:

int selectedYear, int selectedMonth, int selectedDay
Run Code Online (Sandbox Code Playgroud)

我可以将它格式化为"Day,Month dd,yyyy",如下图所示吗?

在此输入图像描述

daf*_*afi 25

使用picker返回的值

    int selectedYear = 2013;
    int selectedDay = 20;
    int selectedMonth = 11;

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, selectedYear);
    cal.set(Calendar.DAY_OF_MONTH, selectedDay);
    cal.set(Calendar.MONTH, selectedMonth);
    String format = new SimpleDateFormat("E, MMM d, yyyy").format(cal.getTime());
Run Code Online (Sandbox Code Playgroud)


Sub*_*ram 5

你可以尝试这个:

SimpleDateFormat sdf = new SimpleDateFormat("EEE-dd-MM-yyyy"); // Set your date format
String currentData = sdf.format(your actual date); // Get Date String according to date format
Run Code Online (Sandbox Code Playgroud)

在这里您可以看到详细信息和所有支持的格式

http://developer.android.com/reference/java/text/SimpleDateFormat.html