gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 08:42:06 25 4
gpt4 key购买 nike

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

    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 小时时间格式。

对于 Android 4(例如 4.4.2),时间格式符合预期。

但是对于 Android 5(例如 5.1),时间格式为 12 小时制。

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

最佳答案

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

DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault());
String formattedDate = dateFormat .format(new Date());

如果这对您不起作用,请尝试这样的操作:

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

关于android - DateFormat.getDateTimeInstance 在 android 5 中使用了错误的本地时间格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31629406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com