package com.cavaness.quartzbook.chapter3;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* 利用SimpleDateFormat()把字符串格式的时间转化为Date类型的时间
* @author Kevin
*
*/
public class DateTest {
private static Log log = LogFactory.getLog(DateTest.class);
/**
* @param args
* @throws ParseException
*/
public static void main(String[] args) throws ParseException {
DateTest dateTest = new DateTest();
try {
dateTest.testSimpleDateFormat();
} catch (ParseException e) {
log.error("转化异常", e);
throw e;
}
}
public void testSimpleDateFormat() throws ParseException {
String stringDate = "2012.08.23";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd");
Date date = null;
try {
date = simpleDateFormat.parse(stringDate);
} catch (ParseException e) {
// e.printStackTrace();
log.error("转化异常", e);
throw e;
}
log.info(date);
}
}
3.利用SimpleDateFormat()把字符串格式的时间转化为Date类型的时间
最新推荐文章于 2022-12-14 11:14:03 发布