Bri*_*ris 6 java localization internationalization
我正在寻找一种方法来告诉Java程序,如果特定区域设置更喜欢在上午12点/下午或24小时时钟显示时间.现在,通常我会使用DateFormat来正确格式化日期,以适合Locale.但是,我正在尝试本地化传输时间表的词干日历显示,这需要对区域设置首选项有一些直接的了解.您可以在此处查看计划示例:
http://onebusaway.org/where/standard/schedule.action?id=1_538
关于如何以编程方式检测12小时AM/PM与24小时的任何想法?
您可以像这样探测它:
boolean hasAmPmClock(Locale locale) {
DateFormat stdFormat = DateFormat.getTimeInstance(DateFormat.SHORT,
Locale.US);
DateFormat localeFormat = DateFormat.getTimeInstance(DateFormat.LONG,
locale);
String midnight = "";
try {
midnight = localeFormat.format(stdFormat.parse("12:00 AM"));
} catch (ParseException ignore) {
}
return midnight.contains("12");
}
Run Code Online (Sandbox Code Playgroud)