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?
sql. Date just represent DATE without time information while java. util. Date represents both Date and Time information.
In fact, the date is stored as milliseconds since the 1st of January 1970 00:00:00 GMT and the time part is normalized, i.e. set to zero. Basically, it's a wrapper around java. util. Date that handles SQL specific requirements.
The java. sql. Date class represents the only date in Java. It inherits the java.
In Java, two dates can be compared using the compareTo() method of Comparable interface. This method returns '0' if both the dates are equal, it returns a value "greater than 0" if date1 is after date2 and it returns a value "less than 0" if date1 is before date2.
Deprecated. This method is deprecated and should not be used because SQL Date values do not have a time component. Parameters: i - the hour value.
What is difference between Java Date and Calendar classes? The difference between Date and Calendar is that Date class operates with specific instant in time and Calendar operates with difference between two dates.
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
java.sql.Date
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With