1
我使用此代碼根據手機語言環境日期格式不得到改變的時候改變區域
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;
}
}
此代碼格式的日期顯示在模擬器和Galaxy Tab的P1000(升級Froyo)完美行爲 但在HTC和Experia還沒有哪個區域選擇的物質顯示單一格式僅
即DD/MM/YYYY 沒有任何別的東西我需要檢查的區域,而在智能手機? 請提供一些幫助。在此先感謝