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 阅读(1929)
评论(0) 编辑 收藏