-3

Can many one help me?

import java.util.Date;


public class DateDemo {

    public static void main(String [] p)
    {
        java.util.Date date1 = new Date();
        @SuppressWarnings("deprecation")
        java.sql.Date date2 = new java.sql.Date(2013, 12, 22);
        System.out.println(date1.compareTo(date2));
    }
}
akuzma
  • 1,592
  • 6
  • 22
  • 49
Dipak M.
  • 11
  • 1
  • 1
  • 1
  • I want to find actually difference in date – Dipak M. Aug 06 '13 at 10:45
  • 1
    What do you mean by "difference in date"? Do you actually *need* `java.sql.Date`? (I would advise you to use Joda Time if possible, and its `LocalDate` type to represent dates without times...) – Jon Skeet Aug 06 '13 at 10:46
  • [This](http://stackoverflow.com/a/2306051/645270) thread is a start – keyser Aug 06 '13 at 10:47
  • I think that answer is here: http://stackoverflow.com/questions/2305973/java-util-date-vs-java-sql-date – lksc Aug 06 '13 at 10:49

2 Answers2

2
  1. As per Javadoc java.sql.Date is a thin wrapper around millisecond value which is used by JDBC to identify an SQL DATE type.

  2. java.sql.Date just represent DATE without time information while java.util.Date represent both Date and Time information. This is the major differences why java.util.Date can not directly map to java.sql.Date.

  3. In order to suppress time information and to confirm with definition of ANSI SQL DATE type, the millisecond values used in java.sql.Date instance must be "normalized by setting the hours, minutes, seconds and milliseconds to zero in the timezone with with DATE instance is associated. In other words all time related information is removed from java.sql.Date class.

Read more: http://javarevisited.blogspot.com/2012/04/difference-between-javautildate-and.html#ixzz2bBWDwBD0

zxc
  • 1,504
  • 3
  • 13
  • 32
0

Date from util package has is combination of date and time while Date from SQL package only represent only Date part. to be precise Date contains year, month and day information while Time means hour, minute and second information. java.util.Date contains all year, month, day, hour, minute and second information. In fact java.sql.Time and java.sql.TimeStamp which represents TIME and TIMESTAMP type of SQL database is more close to java.util.Date, It extends java.util.DATE and if you are using java.util.DATE in your Class to represent DATE value its better to use TIMESTAMP type in Database and java.sql.Time in JDBC or DAO code.

Read more: http://javarevisited.blogspot.com/2012/04/difference-between-javautildate-and.html#ixzz2bBmF4lBd

Mohsin Shaikh
  • 494
  • 1
  • 4
  • 11