String类型转换成date

public static void main(String[] args) throws Exception {
String time = "2017-05-08 17:00:00";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date date_util = sdf.parse(time); //转换为util.date
java.sql.Date date_sql = new java.sql.Date(date_util.getTime());//转换为sql.date
System.out.println(date_util);
System.out.println(date_sql);
String date = sdf.format(date_sql);
System.out.println(date);
date = sdf.format(date_util);
System.out.println(date);
}

你可能感兴趣的:(String类型转换成date)