我从用户那里得到了他在DatePickerDialog中设置的日期。我得到的日期是这种格式:
int selectedYear, int selectedMonth, int selectedDay
我可以将其格式化为“Day,Month dd,yyyy”,如下图所示吗?
答案 0 :(得分:24)
使用选择器返回的值
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());
答案 1 :(得分: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
您可以在此处查看详细信息和所有支持的格式:
http://developer.android.com/reference/java/text/SimpleDateFormat.html
答案 2 :(得分:0)
使用SimpleDateFormat
格式化日期:
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, selectedYear);
cal.set(Calendar.MONTH, selectedMonth);
cal.set(Calendar.DAY_OF_MONTH, selectedDay);
SimpleDateFormat sdf = new SimpleDateFormat();
String DATE_FORMAT = "EE, MMM dd, yyyy";
sdf.applyPattern(DATE_FORMAT);
String formattedDate = sdf.format(cal.getTime());