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
闽公网安备 35060202000074号