Androrider Androrider - 1 year ago 86
Android Question

Get preferred date format string of Android system

Does anybody know how to get the format string used by the system when formatting a date using

DateFormat.getLongDateFormat(Context context).format(Date date)

Answer Source

I wrote a method to detect this format string. ( work for my case).

public static String getDateFormat(Context context){
        // 25/12/2013
        Calendar testDate = Calendar.getInstance();
        testDate.set(Calendar.YEAR, 2013);
        testDate.set(Calendar.MONTH, Calendar.DECEMBER);
        testDate.set(Calendar.DAY_OF_MONTH, 25);

        Format format = android.text.format.DateFormat.getDateFormat(context);
        String testDateFormat = format.format(testDate.getTime());
        String[] parts = testDateFormat.split("/");
        StringBuilder sb = new StringBuilder();
        for(String s : parts){
        return sb.toString().substring(0, sb.toString().length()-1);

Please check the Mark Melling's answer below to have better solution. Mine was just a hack long time ago.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download