Date tdate=new Date(); java.sql.Date date; date=new java.sql.Date(tdate.getYear(),tdate.getMonth(),tdate..getDate()) ; prestate.setDate(3,date);
建议大家看看sun的java doc。那里其实已经写清楚了。 sql.Date是util.Date的子类。 util.Date的精度到毫秒。 这是javadoc的原文: The class Date represents a specific instant in time, with millisecond precision.
java.sql Class Date java.lang.Object | +--java.util.Date | +--java.sql.Date All Implemented Interfaces: Cloneable, Comparable, Serializable public class Date extends DateA thin wrapper around a millisecond value that allows JDBC to identify this as a SQL DATE. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT. To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.
标准的转换方法是: java.sql.Date d = new java.sql.Date((new java.util.Date()).getTime()); 对于sun不建议使用的方法,建议大家不要再用了,以便养成良好的编程习惯。
java.sql.Date date;
date=new java.sql.Date(tdate.getYear(),tdate.getMonth(),tdate..getDate()) ;
prestate.setDate(3,date);
sql.Date是util.Date的子类。
util.Date的精度到毫秒。
这是javadoc的原文:
The class Date represents a specific instant in time, with millisecond precision.
Class Date
java.lang.Object
|
+--java.util.Date
|
+--java.sql.Date
All Implemented Interfaces:
Cloneable, Comparable, Serializable public class Date
extends DateA thin wrapper around a millisecond value that allows JDBC to identify this as a SQL DATE. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT. To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.
java.sql.Date d = new java.sql.Date((new java.util.Date()).getTime());
对于sun不建议使用的方法,建议大家不要再用了,以便养成良好的编程习惯。