0

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

Martin Jäkel
  • 322
  • 6
  • 21
gga
  • 107
  • 7
  • Why can't you just test the locale and use two different SimpleDateFormat patterns? – adelphus May 25 '16 at 11:40
  • 1
    Trying to avoid it, i also have arabic (different number letters) so i'm just trying to find a more elegant solution – gga May 25 '16 at 11:53

1 Answers1

1

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日

ThomasV
  • 779
  • 1
  • 5
  • 20