Can you give me the proper difference between java util Date vs java sql Date

+2 votes
I have a doubt regarding java.util.Date vs java.sql.Date these two dates.

Can you explain me the proper difference between them?
Aug 1, 2019 in Java by Sucheta
15,417 views

2 answers to this question.

+1 vote
  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 represents both Date and Time information. This is the major difference why java.util.Date can not directly map to java.sql.Date.

  3.  To suppress time information and to confirm with the 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 time-zone with DATE instance is associated. In other words, all time-related information is removed from java.sql.Date class.

Thank you, 

I hope this will help you to understand the difference and If you need to know more about Java, join our Java online course today.

answered Aug 2, 2019 by sampriti
• 1,120 points
0 votes

The java.util.date class represents a particular moment in time, with millisecond precision since the 1st of January 1970 00:00:00 GMT (the epoch time). The class is used to keep coordinated universal time (UTC).

The java.sql.Date extends java.util.Date class.

Its main purpose is to represent SQL DATE, which keeps years, months and days. No time data is kept.

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. java.sql.Date should be used only when dealing with databases.

answered Aug 27, 2019 by Sirajul
• 59,230 points

Related Questions In Java

0 votes
1 answer

How to calculate the difference between two date instances in Java?

You can use Joda Time Library. Interval i ...READ MORE

answered May 4, 2018 in Java by Parth
• 4,640 points
940 views
+1 vote
1 answer

Can you please explain the difference between string, string buffer and string builder?

String are immutable where as StringBuffer and ...READ MORE

answered Jul 5, 2019 in Java by Akash
• 160 points
1,328 views
0 votes
1 answer

Can you explain what is the difference between hashtable and hashmap?

Hi, Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for ...READ MORE

answered Aug 15, 2019 in Java by anonymous
750 views
0 votes
1 answer

I am learning looping statements. Can you tell me how 'for-each' works in Java?

While programming we often write code that ...READ MORE

answered Apr 17, 2018 in Java by Rishabh
• 3,620 points
904 views
0 votes
2 answers

How can we convert java.util.Date to java.sql.date in Java?

It's easy to convert a java.util.Date object ...READ MORE

answered Aug 27, 2019 in Java by Sirajul
• 59,230 points
1,316 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 59,230 points
2,283 views
0 votes
2 answers

Integer to String conversion in java

We can do this in 2 ways: String ...READ MORE

answered Jul 28, 2018 in Java by samarth295
• 2,220 points
1,156 views
0 votes
3 answers

String to Double conversion in java

Double temp = Double.valueOf(str); number = temp.doubleValue(); READ MORE

answered Sep 10, 2018 in Java by Sushmita
• 6,920 points
1,710 views
0 votes
2 answers

What is the difference between Map and HashMap in java?

The basic difference is : Map is ...READ MORE

answered Aug 28, 2019 in Java by Sirajul
• 59,230 points
29,469 views
0 votes
2 answers

Please explain me the difference between scanner and the buffer reader?

As per your question for reading a ...READ MORE

answered Aug 27, 2019 in Java by Sirajul
• 59,230 points
3,773 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP