Simpledateformat datefm = new simpledateformat ("yyyy-mm-dd"); // format the current system date
QDs. setdate ("ticket creation date", date. valueof (datefm. Format (New java. util. Date ())));
In this case, the database field is of the date type.
Bytes ------------------------------------------------------------------------------------------------------------
String ticket creation date = messageformat. format ("{0, date, yyyy-mm-dd hh: mm: SS}", new object [] {New Java. SQL. date (system. currenttimemillis ())});
QDs. settimestamp ("ticket date", timestamp. valueof (ticket date); // cannot be forcibly converted
In this case, the database field is of the timestamp (6) type.
Bytes ---------------------------------------------------------------------------------------------------------
Appendix: valueof () methods of several date classes
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 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