📄 getsetlocale.java
字号:
import java.text.*;
import java.util.*;
/** Change the default locale */
public class GetSetLocale {
public static void main(String[] args) {
// 得到并且打印出缺省本地国家代码设置。
Locale l = Locale.getDefault();
System.out.println("Today's Locale is " + l);
// 根据命令行参数设置本地缺省国家代码
switch (args.length) {
case 0:
Locale.setDefault(Locale.TRADITIONAL_CHINESE );
break;
case 1:
throw new IllegalArgumentException();
case 2:
Locale.setDefault(new Locale(args[0], args[1]));
break;
default:
System.out.println("Usage: SetLocale [language [country]]");
}
// 根据设定的缺省国家代码设置日期和数字显示的格式
DateFormat df = DateFormat.getInstance();
NumberFormat nf = NumberFormat.getInstance();
System.out.println("Locale set to " +
Locale.getDefault().getDisplayCountry() +
Locale.getDefault().getDisplayLanguage());
System.out.println(df.format(new Date()));
System.out.println(nf.format(123.4567));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -