testdateformat.java
来自「由浅入深的介绍JAVAse的基本编程思想」· Java 代码 · 共 27 行
JAVA
27 行
import java.util.Date;
import java.util.Locale;
import java.text.DateFormat;
public class TestDateFormat{
public static void main(String args[]){
Date d = new Date();
Locale locale1 = new Locale("zh","CN");
Locale locale2 = new Locale("en","US");
test(d,locale1);
System.out.println("----------------------");
test(d,locale2);
}
public static void test(Date d,Locale locale){
DateFormat df1 = DateFormat.getDateTimeInstance();
DateFormat df2 = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT,locale);
DateFormat df3 = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,locale);
DateFormat df4 = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG,locale);
DateFormat df5 = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,locale);
System.out.println(df1.format(d));
System.out.println(df2.format(d));
System.out.println(df3.format(d));
System.out.println(df4.format(d));
System.out.println(df5.format(d));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?