?? testdateformat.java
字號:
import java.util.*;
import static java.text.DateFormat.*;
import java.text.*;
/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class TestDateFormat
{
public static void main(String[] args)
{
//需要被格式化的日期
Date dt = new Date();
//創(chuàng)建兩個Locale,分別代表中國、美國
Locale[] locales = {Locale.CHINA, Locale.US};
DateFormat[] df = new DateFormat[16];
//為上面兩個Locale創(chuàng)建16個DateFormat對象
for (int i = 0 ; i < locales.length ; i++)
{
df[i * 8] = DateFormat.getDateInstance(SHORT, locales[i]);
df[i * 8 + 1] = DateFormat.getDateInstance(MEDIUM, locales[i]);
df[i * 8 + 2] = DateFormat.getDateInstance(LONG, locales[i]);
df[i * 8 + 3] = DateFormat.getDateInstance(FULL, locales[i]);
df[i * 8 + 4] = DateFormat.getTimeInstance(SHORT, locales[i]);
df[i * 8 + 5] = DateFormat.getTimeInstance(MEDIUM , locales[i]);
df[i * 8 + 6] = DateFormat.getTimeInstance(LONG , locales[i]);
df[i * 8 + 7] = DateFormat.getTimeInstance(FULL , locales[i]);
}
for (int i = 0 ; i < locales.length ; i++)
{
switch (i)
{
case 0:
System.out.println("-------中國日期格式--------");
break;
case 1:
System.out.println("-------美國日期格式--------");
break;
}
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));
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -