4.利用DateFormat

package com.cavaness.quartzbook.chapter3;

import java.text.DateFormat;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 利用DateFormat
 * @author Kevin
 *
 */
public class DateTest {
	private static Log log = LogFactory.getLog(DateTest.class);

	/**
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		DateTest dateTest = new DateTest();
		dateTest.testDateFormat();

	}
	
	/**
	 * DateFormat是个抽象类,不能实例化,它的静态方法getDateInstance()方法返回的DateFormat对象,其实是它的子类SimpleDateFomat对象
	 * 也就是说,想得到一个SimpleDateFomat对象,最直接的是new SimpleDateFomat(),也可以DateFormat.getDateInstance()
	 */
	public void testDateFormat() {
		DateFormat dateFormat = DateFormat.getDateTimeInstance(); 
		log.info(dateFormat.format(new Date())); // 2012-8-1 14:34:51
		
		DateFormat dateFormat2 = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
		log.info(dateFormat2.format(new Date())); // 12-8-1 下午2:35;这两句代码跟如下的两句代码效果一样SimpleDateFormat simpleDateFormat = new SimpleDateFormat(); // 用默认的模式和默认语言环境的日期格式符号构造 SimpleDateFormat。   log.info(simpleDateFormat.format(new Date())); // 12-8-1 上午11:28   

		
		DateFormat dateFormat3 = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
		log.info(dateFormat3.format(new Date())); // 2012-8-1 14:36:37
		
		DateFormat dateFormat4 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
		log.info(dateFormat4.format(new Date())); // 2012年8月1日 下午02时40分13秒
		
		DateFormat dateFormat5 = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
		log.info(dateFormat5.format(new Date())); // 2012年8月1日 星期三 下午02时41分11秒 CST
		
		
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值