top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is difference between java.util.Date and java.sql.Date?

+1 vote
865 views
What is difference between java.util.Date and java.sql.Date?
posted Sep 19, 2017 by Pankaj Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

java.util.Date contains information about the date and time whereas java.sql.Date contains information only about the date, it doesn’t have time information. So if you have to keep time information in the database, it is advisable to use Timestamp or DateTime fields.

answer Sep 20, 2017 by Sourav Kumar
0 votes

Here are few difference is :

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

    • 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.
    • 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.
answer Apr 3, 2019 by Siddhi Patel
Similar Questions
+3 votes

How to print current date and time in C/C++, sample program will help?

+2 votes

I always hate dealing with date/time stuff in php - never get it even close until an hour or two goes by....

anyway I have this:

// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);

Currently the results are:

exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.

BUT time_left is 07:43:04 when it should be only "00:43:04". So - where is the hour value of '07' coming from?? And how do I get this right?

...