package com.cavaness.quartzbook.chapter3;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* 测试SimpleDateFormat()
* @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.testSimpleDateFormat();
}
public void testSimpleDateFormat() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(); // 用默认的模式和默认语言环境的日期格式符号构造 SimpleDateFormat。
log.info(simpleDateFormat.format(new Date())); // 12-8-1 上午11:28
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy.MM.d");
log.info(simpleDateFormat2.format(new Date())); // 2012.08.1
SimpleDateFormat simpleDateFormat3 = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
log.info(simpleDateFormat3.format(new Date())); // 2012.08.01 11:32:44
SimpleDateFormat simpleDateFormat4 = new SimpleDateFormat("yyyy.MM.dd E HH:mm:ss");
log.info(simpleDateFormat4.format(new Date())); // Message:2012.08.01 星期三 11:34:51
SimpleDateFormat simpleDateFormat5 = new SimpleDateFormat("时间:yyyy.MM.dd E HH:mm:ss");// 时间格式中,非ASCII,可以直接写上去,比如"时间:"
log.info(simpleDateFormat5.format(new Date())); // 时间:2012.08.01 星期三 11:37:01
SimpleDateFormat simpleDateFormat6 = new SimpleDateFormat("时间'time':yyyy.MM.dd E HH:mm:ss");// 时间格式中,ASCII,不可以直接写上去,加上单引号
log.info(simpleDateFormat6.format(new Date())); // 时间time:2012.08.01 星期三 11:38:57
}
}
2.测试SimpleDateFormat()
最新推荐文章于 2021-02-11 22:31:12 发布