7

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
  • 4
    Somtimes I think to make programmers life harder Commented Jan 20, 2010 at 19:25
  • And then there's JODA... Commented Jan 20, 2010 at 20:20
  • But you skipped over 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. Commented Jan 20, 2010 at 23:10

3 Answers 3

11

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

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

3

The java.sql.Date is a subclass (an extension) of java.util.Date.
What changed in java.sql.Date:

  1. toString() generates a different string representation: yyyy-mm-dd
  2. a static valueOf(String) methods to create a Date from a String with above representation
  3. 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.