DateFormat.getDateTimeInstance在android 5中使用了错误的本地时间格式

DateFormat.getDateTimeInstance在android 5中使用了错误的本地时间格式,android,localization,Android,Localization,我正在使用以下代码格式化输出: DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); Date date = new Date(cursor.getLong(cursor.getColumnIndex(MyContentProvider.KEY_TIME_START))); TextView textView = (TextView) view.findVi

我正在使用以下代码格式化输出:

    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
    Date date = new Date(cursor.getLong(cursor.getColumnIndex(MyContentProvider.KEY_TIME_START)));
    TextView textView = (TextView) view.findViewById(R.id.column_time_start);
    textView.setText(df.format(date));
例如德语,我希望采用当地24小时制

使用安卓4(例如4.4.2)时,时间的格式与预期一致

但在Android 5(例如5.1)中,时间是以12小时的时间格式设置的


有人知道解决这个问题的好办法吗

尝试使用
DateFormat.getDateTimeInstance(int,int,Locale)

如果这对您不起作用,请尝试以下方法:

Locale current = getResources().getConfiguration().locale;
// Find out what the current locale is and format your date based on that

你考虑过使用android.text.format.DateFormat吗?它应该考虑用户的偏好。它的工作原理是:
textView.setText(getDateFormat(context.format(date)+“”+getTimeFormat(context.format(date))但现在我必须依次格式化日期和时间。还有其他解决方案吗?
DateFormat.getTimeInstance(DateFormat.SHORT,Locale.getDefault())
似乎有问题,因为Android 5:-(和
getTimeFormat(上下文)
调用时不幸没有样式参数。我遇到了同样的问题:作为程序员和用户!我的Oxygen OS 2.1基于Android 5.1,所有的应用程序,如Facebook、FitBit和我自己的——都产生了错误的12小时格式,尽管我在德国将24小时设置为我的格式。为什么没有人真正关注这个错误?sol不是吗“我解决了这个问题。输出看起来和以前一样。@samo请看编辑。不过,这将是您的更多手动工作。谢谢您的帮助。
android.text.format.DateFormat
works(见上文)。
Locale current = getResources().getConfiguration().locale;
// Find out what the current locale is and format your date based on that