Repository navigation
Expand file tree
/
Copy pathTestDateFormat.java
More file actions
48 lines (44 loc) · 1.75 KB
/
Copy pathTestDateFormat.java
File metadata and controls
48 lines (44 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.text.DateFormat;
import java.text.Format;
import java.util.Date;
import java.util.Locale;
public class TestDateFormat
{
public static void main(String[] args)
{
Date dt=new Date();
Locale[] locales={Locale.CHINA,Locale.US};
DateFormat[] df=new DateFormat[16];
//为了上面两个Locale创建16DateFormat对象
for(int i=0;i<locales.length;i++)
{
df[i*8]=DateFormat.getDateInstance(DateFormat.SHORT,locales[i]);
df[i*8+1]=DateFormat.getDateInstance(DateFormat.MEDIUM,locales[i]);
df[i*8+2]=DateFormat.getDateInstance(DateFormat.LONG,locales[i]);
df[i*8+3]=DateFormat.getDateInstance(DateFormat.FULL,locales[i]);
df[i*8+4]=DateFormat.getTimeInstance(DateFormat.SHORT,locales[i]);
df[i*8+5]=DateFormat.getTimeInstance(DateFormat.MEDIUM,locales[i]);
df[i*8+6]=DateFormat.getTimeInstance(DateFormat.LONG,locales[i]);
df[i*8+7]=DateFormat.getTimeInstance(DateFormat.FULL,locales[i]);
for(i=0;i<locales.length;i++)
{
switch (i)
{
case 0:
System.out.println("------中国日期格式----");
break;
case 1:
System.out.println("------美国日期格式----");
}
System.out.println("SHORT格式的日期格式:"+df[i*8].format(dt));
System.out.println("MEDIUM格式的日期格式:"+df[i*8+1].format(dt));
System.out.println("LONG格式的日期格式:"+df[i*8+2].format(dt));
System.out.println("FULL格式的日期格式:"+df[i*8+3].format(dt));
System.out.println("SHORT格式的时间格式:"+df[i*8+4].format(dt));
System.out.println("MEDIUM格式的时间格式:"+df[i*8+5].format(dt));
System.out.println("LONG格式的时间格式:"+df[i*8+6].format(dt));
System.out.println("FULL格式的时间格式:"+df[i*8+7].format(dt));
}
}
}
}