Android 更改区域设置时不会更改DateFormat
我正在使用此代码根据电话地区设置日期格式Android 更改区域设置时不会更改DateFormat,android,localization,Android,Localization,我正在使用此代码根据电话地区设置日期格式 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.getDateInstanc
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;
}
}
此代码在emulator和galaxy tab p1000(froyo)上显示了完美的行为
但在htc和experia上,无论选择哪种语言环境,都只显示单一格式
i、 e.年月日
在使用智能手机时,我还需要检查语言环境吗?
请提供一些帮助。提前感谢您可以查看链接,也许您可以从这里获得一些想法
在代码之后
calendar.setTime(日期)代码>
只需将日历转换为字符串。您可以查看链接,也许您可以从这里了解一些信息
在代码之后
calendar.setTime(日期)代码>
只需将日历转换为字符串即可