首页 > 代码库 > DateFormatUtil格式化时间

DateFormatUtil格式化时间

package org.xiaowu.json.demo;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;
import org.junit.Test;

public class DateFormatUtilDemo {
    
    @Test
    public void Test1(){
        String format1 = DateFormatUtils.ISO_DATE_FORMAT.format(new Date());
        System.out.println("format1:"+format1);
    }

    @Test
    public void Test2(){
        String format1 = DateFormatUtils.ISO_DATE_TIME_ZONE_FORMAT.format(new Date());
        System.out.println("format1:"+format1);
    }
    
    @Test
    public void Test3(){
        String format1 = DateFormatUtils.ISO_DATETIME_FORMAT.format(new Date());
        System.out.println("format1:"+format1);
    }
    
    @Test
    public void Test4(){
        String format1 = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(new Date());
        System.out.println("format1:"+format1);
    }
    
    @Test
    public void Test5(){
        String format1 = DateFormatUtils.ISO_TIME_FORMAT.format(new Date());
        System.out.println("format1:"+format1);
    }
    
    @Test
    public void Test6(){
        String format1 = DateFormatUtils.ISO_TIME_NO_T_FORMAT.format(new Date());
        System.out.println("format1:"+format1);
    }
    
    @Test
    public void Test7(){
        String format1 = DateFormatUtils.ISO_TIME_NO_T_TIME_ZONE_FORMAT.format(new Date());
        System.out.println("format1:"+format1);
    }
    
    @Test
    public void Test8(){
        String format1 = DateFormatUtils.ISO_TIME_TIME_ZONE_FORMAT.format(new Date());
        System.out.println("format1:"+format1);
    }

    @Test
    public void Test9(){
        String format1 = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        System.out.println("format1:"+format1);
    }
    
    @Test
    public void Test10(){
        String format1 = DateFormatUtils.format(Calendar.getInstance().getTimeInMillis(), "yyyy-MM-dd HH:mm:ss");
        System.out.println("format1:"+format1);
    }
    
    
    //项目中代码实例
//    DateFormatUtils.format(aucLot.startTime(), "yyyyMMdd")
}

 

DateFormatUtil格式化时间