Search code examples
androidsimpledateformatchinese-localeandroid-date

Date with format and locale


I am trying to get the date with this pattern - "dd/MM/yyyy". So far i've used SimpleDateFormat to achieve it, but now i need to also support Chinese in my app and it's not giving me the result i need.

I'm trying to make it look like the pattern with attention to the locale: English: 16/05/2016 Chinese: 2016年05月16日

I tried different options - android.text.format.DateUtils.formatDateTime android.text.format.DateFormat.getDateFormat

but couldn't get the result i wanted. Thanks


Solution

  • If you want specific patterns, you have to test the locale and apply the format you want.

    For your english and chinese formats :

    CharSequence englishDate = DateFormat.format("dd/MM/yyyy", date);
    CharSequence chineseDate = DateFormat.format("yyyy年MM月dd日", date);
    

    Results are : 25/05/2016 and 2016年05月25日