Android Date Formatting as per locale

Dhrupal
1 min readJun 15, 2015

In Android to formate the date

Date date = Calendar.getInstance().getTime(); DateFormat formatter = new SimpleDateFormat(“dd, MMM yyyy”);

String today = formatter.format(date); System.out.println(“Today’s Date:”+ today);

This will give date like 15 June 2015. If we change Language of device to German then it will give 15 Juni 2015 but actually 15. Juni 2015 is right format for German date format.

Android DateFormat API provides a method getBestDateTimePattern(Locale locale, String skeleton) in which you just need to pass locale and the things you need formatted irrelevant to order.

String format = DateFormat.getBestDateTimePattern(Locale.getDefault(), “dd, MMM yyyy”);

System.out.println(“Today’s Date(German): “ + DateFormat.format(format, d));

--

--

Dhrupal

Passionate to try new, be better from yesterday, hold core values, help selflessly, be humble, embrace life at it’s awesome and at worst. JUST SHINE FOR SELF.