I am using this code to format the date according to phone locale
private String localisedDate(String date) {
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
try{
Date d1 = df.parse(date);
Locale myLocale = Locale.getDefault();
DateFormat sdf = DateFormat.getDateInstance(DateFormat.SHORT, myLocale);
StringBuffer sb = new StringBuffer();
FieldPosition fp = new FieldPosition(DateFormat.YEAR_FIELD);
sb = sdf.format(d1, sb, fp);
sb.replace(sb.lastIndexOf("/") ,sb.length(), new SimpleDateFormat("/yyyy").format(d1) );
Log.e("date",sb.toString());
return sb.toString();
}catch (Exception e) {
// TODO: handle exception
return date;
}
}
This code shows perfect behavior on emulator and on galaxy tab p1000(froyo) But on htc and experia no matter which locale selected shows single format only
i.e. dd/MM/yyyy is there any thing else i need to check for locale while on smartphone? please provide some help. Thanks in advance