?
最近整理的java 有关于日期格式转换的方法。
如何将"yyyy-mm-dd"格式的字符串转换为java.sql.Date
方法1
SimpleDateFormat bartDateFormat =??
??????? new SimpleDateFormat("yyyy-MM-dd");??
?????? String dateStringToParse = "2007-7-12";??
?????? try {??
??????? java.util.Date date = bartDateFormat.parse(dateStringToParse);??
??????? java.sql.Date sqlDate = new java.sql.Date(date.getTime());
??????? System.out.println(sqlDate.getTime());??
?????? }??
?????? catch (Exception ex) {??
??????? System.out.println(ex.getMessage());??
?????? }
------------------------------------------------------------
方法2
?????? String???? strDate???? =???? "2002-08-09";???
?????? StringTokenizer???? st???? =???? new???? StringTokenizer(strDate,???? "-");???
?????? java.sql.Date???? date???? =???? new???? java.sql.Date(Integer.parseInt(st.nextToken()),
??????????????? Integer.parseInt(st.nextToken()),
???????????????? Integer.parseInt(st.nextToken()));
??
java.util.Date和java.sql.Date的异同 java.sql.Date,java.sql.Time和java.sql.Timestamp三个都是java.util.Date的子类(包装类)。?