Date formatting based on user locale on android

前端 未结 6 839
孤城傲影
孤城傲影 2020-11-27 04:35

I want to display a date of birth based on the user locale. In my application, one of my fields is the date of birth, which is currently in the format dd/mm/yyyy

6条回答
  •  -上瘾入骨i
    2020-11-27 05:24

    To get the date format pattern you can do :

    Format dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
    String pattern = ((SimpleDateFormat) dateFormat).toLocalizedPattern();
    

    After that, you can format your input as per the pattern.

提交回复
热议问题