Android - Date format in "Day, Month dd, yyyy"

I get from the user the date that he sets in DatePickerDialog. The date I receive is in this format:

int selectedYear, int selectedMonth, int selectedDay 

Can I format it like "Day, Month dd, yyyy" as shown in the image below?

enter image description here

+6
source share
3 answers

Using the values โ€‹โ€‹returned from the collector

  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()); 
+21
source

You can try the following:

 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 the details and the entire supported format:

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

+6
source

Use the SimpleDateFormat format 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(pattern); String formattedDate = sdf.format(cal.getTime()); 
+1
source

Source: https://habr.com/ru/post/957910/


All Articles