Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Date class in Package java.util & Package java.sql

Tags:

java

date

In java, both the java.util and the java.sql package contain a Date class, So what is the difference between them?

If one Date class is present in Java then what is the need of another Date class?

like image 521
ram Avatar asked Mar 14 '11 12:03

ram


People also ask

What is the difference between Java Util date and Java sql date?

sql. Date just represent DATE without time information while java. util. Date represents both Date and Time information.

Is Java Util date a class?

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).

How do I calculate the difference between two Java Util dates?

Find the time difference between two dates in millisecondes by using the method getTime() in Java as d2. getTime() – d1. getTime(). Use date-time mathematical formula to find the difference between two dates.

Which package has date class in Java?

Java provides the Date class available in java. util package, this class encapsulates the current date and time.


1 Answers

From the JavaDoc of 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.

To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.

Explanation: A java.util.Date represents date and time of day, a java.sql.Date only represents a date (the complement of java.sql.Date is java.sql.Time, which only represents a time of day, but also extends java.util.Date).

like image 141
Sean Patrick Floyd Avatar answered Oct 29 '22 04:10

Sean Patrick Floyd