Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I format Date with Locale in Android

I am using SimpleDateFormat to format my date "dd Mmm yyy" format but I want Mmm to be translated to Malay. I am using below code to do so but unable to get the expected result.

SimpleDateFormat sdf = new SimpleDateFormat(format,new Locale("ms","MY"));
return sdf.format(date);
like image 873
Komal Gupta Avatar asked Dec 05 '22 18:12

Komal Gupta


1 Answers

You Should Try This Way to format locale date:

DateFormat f = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault());
String formattedDate = f.format(new Date());
System.out.println("Date: " + formattedDate);

I Hope this will work. Reference link: Localized date format in Java

like image 116
Sackurise Avatar answered Dec 10 '22 13:12

Sackurise