/** * String轉換爲java.sql.Date * * @param strDate * @return */ public static java.sql.Date strToDate(String strDate) { String str = strDate; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date d = null; try { d = format.parse(str); } catch (Exception e) { e.printStackTrace(); } java.sql.Date date = new java.sql.Date(d.getTime()); return date; } /** * 返回Time格式的時間 * * @param strDate * @return */ public static java.sql.Timestamp strToTime(String strDate) { Timestamp ts = new Timestamp(System.currentTimeMillis()); try { ts = Timestamp.valueOf(strDate); System.out.println(ts); } catch (Exception e) { e.printStackTrace(); } return ts; }