HI
I like to know why there are two Date classes in two different packages one in java.util.Date and one in java.sql.Date?
Whats the use of having two Date classes?
3 Answers
java.util.Date is Java's Date data type.
java.sql.Date is a JDBC wrapper for SQL dates.
The two are represented completely differently internally.
.NET has the same concepts (but a better naming convention to differentiate the two in my opinion) with System.DataTime and System.Data.SqlTypes.SqlDateTime
Comments
A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.
Comments
The java.sql.Date is a subclass (an extension) of java.util.Date.
What changed in java.sql.Date:
toString()generates a different string representation:yyyy-mm-dd- a static
valueOf(String)methods to create a Date from a String with above representation - the getters and setter for hours, minutes and seconds are deprecated
The java.sql.Date class is used with JDBC and it was intended to not have a time part, that is, hours, minutes, seconds, and milliseconds should be zero... but this is not enforced by the class.
java.util.Calendar! Ironically, there's not a single one of these (JDK classes) that you should ever actually use (unless forced). Joda-Time is the only date/time API done right.