看一下实际的android.text.format.DateFormat.is24HourFormat方法的
source code,您将看到它们是如何做到的:
Locale locale = context.getResources().getConfiguration().locale;
java.text.DateFormat natural =
java.text.DateFormat.getTimeInstance(
java.text.DateFormat.LONG, locale);
if (natural instanceof SimpleDateFormat) {
SimpleDateFormat sdf = (SimpleDateFormat) natural;
String pattern = sdf.toPattern();
if (pattern.indexOf('H') >= 0) {
value = "24";
} else {
value = "12";
}
} else {
value = "12";
}
因此,您可以根据您获取区域设置的方式进行调整.