带区域设置的日期格式 [英] Date Format with Locale
问题描述
我想根据每个国家的日期格式显示日期.我尝试了很多方法终于找到了这个例子
I want to display date according to each country's date format. I have tried many ways finally I found this example
http://www.java2s.com/Code/Java /Data-Type/DateFormatwithLocale.htm
哪个可以完美输出我的意思.像德国这样的某些国家/地区不会使用 12hr 格式,而是使用 24hr 格式且没有没有AM/PM .有些国家(如 US )使用12小时格式.
Which gives the perfect output of what I meant. Some countries like Germany won't use 12hr formats instead they uses 24 hr formats with no AM/PM. While some countries like US uses 12hr formats.
但是我发现,在运行此java类时,它会返回预期的正确输出,但是在Android项目中运行时,它会返回类似的结果
But I found that while running this java class it returns the correct output as expected but while running this inside an Android project it returns something like this
I/System.out: Locale: en_US
I/System.out: Jan 23, 2018 5:26:41 AM
I/System.out: Jan 23, 2018 5:26:41 AM
I/System.out: Jan 23, 2018 5:26:41 AM
I/System.out: Jan 23, 2018 5:26:41 AM
I/System.out: Jan 23, 2018 5:26:41 AM
I/System.out: Locale: de_DE
I/System.out: 23.01.2018 5:26:41 vorm.
I/System.out: 23.01.2018 5:26:41 vorm.
I/System.out: 23.01.2018 5:26:41 vorm.
I/System.out: 23.01.2018 5:26:41 vorm.
I/System.out: 23.01.2018 5:26:41 vorm.
在语言环境:en_US的情况下,这是预期的,但在语言环境:de_DE的情况下,则期望该语言没有"vorm".
In case of Locale: en_US it is as expected but in case of Locale: de_DE it is expected not to have that "vorm.".
有人可以解释这种行为吗?
Could anyone explain this behavior?
推荐答案
最后我找到了答案.. :)谢谢Ole V.V.
Finally I found the answer.. :) Thanks Ole V.V.
这里是: Java DateFormat. Android中的SHORT无法正常工作
这篇关于带区域设置的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!