问题
I get from the user, the date he sets in a DatePickerDialog. The date i get is in this format:
int selectedYear, int selectedMonth, int selectedDay
Can i format it to be like this "Day, Month dd, yyyy" as shown in the picture below?

回答1:
Using the values returned from 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());
回答2:
You can Try This:
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
Here you can see details and all supported format:
http://developer.android.com/reference/java/text/SimpleDateFormat.html
回答3:
Use a SimpleDateFormat
to format the date:
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());
来源:https://stackoverflow.com/questions/19928757/android-format-date-to-day-month-dd-yyyy