1

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

4

1 回答 1

1

你可以查看这个链接,也许你可以从这里得到一些想法。

代码之后

calendar.setTime(date);

只需转换calendar为字符串。

于 2012-07-09T05:52:48.553 回答