力的Andr​​oid DateUtils.getRelativeDateTimeString()忽略设备的语言环境? [英] Force Android DateUtils.getRelativeDateTimeString() to ignore the device locale?

查看:591
本文介绍了力的Andr​​oid DateUtils.getRelativeDateTimeString()忽略设备的语言环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用返回如昨天或2小时前非常漂亮值 android.text.format.DateUtils 相关API中 - 但我的应用程序不支持每一种语言的Andr​​oid一样。所以,我默认为英语,但我并不支持所有语言,相对字符串显示在设备的设置。

I've found using the android.text.format.DateUtils relative APIs that return values like "yesterday" or "2 hours ago" very nice - but my app does not support every language Android does. So, I default to English, but for every language I don't support, the relative string shows in the device's setting.

例如,如:

最后的尝试:脑水肿11 minutos

我想使API调用默认为英语,我不支持任何语言。不过,我没有看到任何地方设置语言环境的API调用 - 我希望我只是失踪它的地方。

I'd like to make the API call default to English for any languages I don't support. However, I don't see anywhere to set the Locale for the API call - I'm hoping I'm just missing it somewhere.

有没有一种方法来设置语言环境只为API调用,忽略了设备设置?

Is there a way to set the Locale just for the API call, ignoring the device setting?

推荐答案

按照 DateUtils 类的源$ C ​​$ c将其同时使用 Resource.getSystem() Locale.getDefault()格式化日期和时间的方法。您可以更改默认的区域设置使用 Locale.setDefault()方法,但我不认为这是可能改变返回 Resource.getSystem()法的价值。你可以尝试将默认区域设置更改为 Locale.US ,但在我看来,结果会在这种情况下会更糟糕。

According to the source code of the DateUtils class it uses both Resource.getSystem() and Locale.getDefault() method for formatting date and time. You can change the default Locale using Locale.setDefault() method but I don't think it's possible to change the return value of the Resource.getSystem() method. You can try to change the default locale to Locale.US but it seems to me that results will be even worse in this case.

这篇关于力的Andr​​oid DateUtils.getRelativeDateTimeString()忽略设备的语言环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆