明確使用withLocale
將語言環境設置爲德語會導致am/pm字符串在時間值中進行本地化,但不會轉換爲適用於該語言環境的24小時時間格式。使用Joda DateTimeFormatter.withLocale()僅影響am/pm的字符串值,而不是時間格式
當創建新進程時,Locale.setLocale(Locale.GERMAN);
已完成,格式正確。
不應該withLocale()
影響有問題的語言環境的所有方面?
// Code snippet where call is being made:
Log.d(TAG, "XYZZY getDefault(): " + Locale.getDefault().toString());
DateTimeFormatter timeFormat = DateTimeFormat.shortTime()
.withLocale(Locale.getDefault());
Log.d(TAG, "XYZZY timeFormat.locale: " +
timeFormat.getLocale().toString());
dateString = alarmTime.toString(timeFormat);
Log.d(TAG, "XYZZY dateString: "+ dateString);
當變量alarmTime
具有下午11時00的值(2300小時):41.492(23609)::
10-04 14:17 XYZZY getDefault():EN_US
10 -04 14:17:41.493(23609):XYZZY timeFormat.locale:EN_US
10-04 14:17:41.495(23609):XYZZY dateString:11:00 PM
現在切換到德語語言環境並重新執行相同的代碼,請注意 字符串「PM」更改爲德語,但不是時間格式(後綴 應該被抑制,時間值應爲23:00):
10-04 14:18 :15.066(23609):XYZZY getDefault():de_DE
10-04 14:18:15.066(23609):XYZZY timeFormat.locale:de_DE
10-04 14:18:15.067(23609):XYZZY dateString:11 :00 nachm。
等待的過程中消失,重新啓動,使語言爲 德國,現在正在返回德國在正確的時間格式:
10-04 14:18:54.497( 23881):XYZZY getDefault():de_DE這個
10-04 14:18:54.497(23881):XYZZY timeFormat.locale:de_DE這個
10-04 14:18:54.498(23881):XYZZY dateString:23:00
你是如何每次創建alarmTime的?在括號中是進程ID號?爲什麼情況1和情況2相同,如果你再次執行你的代碼? – Vahid
進程ID相同是我看到的基本問題。當進程消失並開始一個新的(語言環境設置爲德語)時,我得到所需的結果(情況3)。 –
你可以分享你創建alarmTime的代碼嗎?而且,你是在爲Android開發嗎? – Vahid