SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd"); //格式化當前系統日期
qds.setDate("制單日期", Date.valueOf(dateFm.format(new java.util.Date())));
此種情況數據庫的字段為Date型
------------------------------------------------------------------------------------------------------------
String 制單日期 = MessageFormat.format("{0,date,yyyy-MM-dd HH:mm:ss}", new Object[] { new java.sql.Date(System.currentTimeMillis()) });
qds.setTimestamp("制單日期", Timestamp.valueOf(制單日期)); // 不能強行轉換
此種情況數據庫的字段為Timestamp(6)型
---------------------------------------------------------------------------------------------------------
附:幾個Date類的valueOf()方法
1. java.sql.Date.valueOf(java.lang.String)
public static Date valueOf(String s)
Converts a string in JDBC date escape format to a Date value.
Parameters:
s - a String object representing a date in in the format "yyyy-mm-dd"
Returns:
a java.sql.Date object representing the given date
Throws:
IllegalArgumentException - if the date given is not in the JDBC date escape format (yyyy-mm-dd)
2. java.sql.Time.valueOf(java.lang.String)
public static Time valueOf(String s)
Converts a string in JDBC time escape format to a Time value.
Parameters:
s - time in format "hh:mm:ss"
Returns:
a corresponding Time object
3. java.sql.Timestamp.valueOf(java.lang.String)
public static Timestamp valueOf(String s)
Converts a String object in JDBC timestamp escape format to a Timestamp value.
Parameters:
s - timestamp in format yyyy-mm-dd hh:mm:ss.fffffffff
Returns:
corresponding Timestamp value
Throws:
IllegalArgumentException - if the given argument does not have the format yyyy-mm-dd hh:mm:ss.fffffffff
本文引用通告地址: http://blog.csdn.net/jwbecalm/services/trackbacks/444843.aspx
posted on 2005-08-28 05:26
jacky 閱讀(1934)
評論(0) 編輯 收藏