Java_DateFormat紀要|時間日期格式化

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));  
    } 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章