How to get user-selected date format in Android? How to get user-selected date format in Android? android android

How to get user-selected date format in Android?


In an application I'm currently developing I use the following, which I believe will do what you require

final String format = Settings.System.getString(getContentResolver(), Settings.System.DATE_FORMAT);if (TextUtils.isEmpty(format)) {  dateFormat = android.text.format.DateFormat.getMediumDateFormat(getApplicationContext());} else {  dateFormat = new SimpleDateFormat(format);}


The DateFormat.getDateFormat works as expected. It returns one of three possible formats:

  1. MM/DD/YYYY
  2. DD/MM/YYYY
  3. YYYY/MM/DD

I'm not sure how you set your "Sat, 31 Dec 2011" format, but as far as I know stock Android allows to set only one of three mentioned formats (Settings -> Date and Time -> Select Date Format).

enter image description here


Try this

Date inDate = inFormat.parse(in);DateFormat outFormat = android.text.format.DateFormat.getDateFormat(context);out=outFormat.format(inDate);