当前我使用new SimpleDateFormat("h:mm a", Locale.getDefault())
在应用程序中显示时间。它总是像12:00 AM
一样显示时间,设备语言设置为英语(美国(或英语(英国(。对于语言设置为英语(英国(的设备,我想改变这种行为并以24小时格式显示时间。有什么好办法吗?
使用DateFormat.getDateInstance(int样式,区域设置区域设置(
使用此[简单易懂:(]:
final Calendar calendar = Calendar.getInstance();
String locale = Locale.getDefault().toString();
if (locale.equals("en_US")) {
SimpleDateFormat US = new SimpleDateFormat("h:mm a");
String us = US.format(calendar.getTime());
Log.i ("US - Time is : ",us);
} else if (locale.equals("en_GB")) {
SimpleDateFormat UK = new SimpleDateFormat("hh:mm:ss");
String uk = UK.format(calendar.getTime());
Log.i ("UK - Time is : ",uk);
} else {
Log.i("Your Location ",locale);
}}
我已经创建了一个条件,它可以根据位置更改时间[区域设置]!希望有用。
祝你好运。