java.text.DateFormat
DateFormat:
特點:DateFormat是一個抽象接口;主要用途用作Date日期格式格式化;
以下是一則小Demo;以供參考:
/**
* 參數日期格式化;
* DateFormat是一個抽象接口;主要用途用作Date日期格式格式化;
* 對應支持四種形式的轉換:FULL,LONG,SHORT,MEDIUM;
*/
public static void date_Format() {
System.out.println("使用DateFormat類獲取系統的當前時間的示例如下所示:");
Date date = new Date();
DateFormat shortDateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
DateFormat mediumDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
DateFormat longDateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
DateFormat fullDateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
System.out.println("SHORT 模式的日期爲:" + shortDateFormat.format(date));
System.out.println("MEDIUM 模式的日期爲:" + mediumDateFormat.format(date));
System.out.println("LONG 模式的日期爲:" + longDateFormat.format(date));
System.out.println("FULL 模式的日期爲:" + fullDateFormat.format(date));
}