Java——Java日期转Sql日期
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Text { public static void main(String[] args) { String joinDate = "2012-3-21 11:7:5"; //开始是String=”2012-3-21 11:7:5“ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //变成Wed Mar 21 11:07:05 CST 2012 java.util.Date javaDate= null; try { javaDate= sdf.parse(joinDate); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } //剩下这个2012-3-21 java.sql.Date sqlDate = new java.sql.Date(javaDate.getTime()); //剩下这个2012-3-21 System.out.println(sqlDate); //格式化再输出 System.out.println(sdf.format(sqlDate)); } }
逃避不一定躲得过,面对不一定最难过