package com.tender.news.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.lang.StringUtils;
public class Test {
public static void main(String[] args)throws Exception {
String str="2012-09-06";
java.util.Date dateStr=null;
dateStr=toSqlDate(str, "yyyy-MM-dd");
System.out.println(dateStr);
}
public static java.sql.Date toSqlDate(String dateStr, String pattern){
java.sql.Date date = null;
if(StringUtils.isNotEmpty(dateStr)){
try {
Date birth = null;
SimpleDateFormat format = new SimpleDateFormat(pattern);
birth = format.parse(dateStr);
date = new java.sql.Date(birth.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
}
return date;
}
}