JAVA DATE, UTILL DATE, AND SQL DATE.
JAVA DATE
· In java does not have a specific build in class for represents the date. We can import java.time package to represent date and time. Also, we can use java.utill.Date class to represent date and time.
· Java.utill.date class has Date, Time, and Timestamp subclasses.
public class Date
extends Object
implements Serializable, Cloneable, Comparable<Date>
· The Date class represents a specific instant in time with milliseconds.
· Date class represents dates as year, month, day, hour, and second values.
· The Date class is also used to determine Coordinated Universal Time(UTC) depending on the host environment of Java Virtual Machine.
UTILL DATE
· In Java, date and time represent using java.utill.Date class. It provides methods and constructors to represent date and time.
· Using java.utill.Date, Java represents specific time using the epoch time. Epoch time is a number of seconds since 00:00:00, 1st January of 1970. Also keep UTC(Coordinated Universal time) standard to represent the time.
· The java.util.Date class implements Serializable, Cloneable and Comparable<Date> interface. It is inherited by java.sql.Date, java.sql.Time and java.sql.Timestamp interfaces.
Get Hasara Ismini Biseka’s stories in your inbox
Join Medium for free to get updates from this writer.
There are two ways to initialize Java date.
01. By calling the constructor
Date date = new Date();
02. By passing a number of milliseconds since the epoch
Long timestamp = 1643631171; // 31st January of 2022 17:43:10 UTC
Date date= new Date(timestamp);
· Many operating systems do not use leap second and getting to cound 1 day using 86400 seconds.
· This contains all the year, month, day, hour, minute, and second information.
SQL DATE
· In SQL, Date represents using java.sql.Date class. It keeps years, months, and days. And keep in mind there is no keep time data in it. It is the main difference between java date and sql date.
· Sql date is stored as milliseconds using epoch time since January 1, 1970, 00:00:00 UCT.
· Java.sql.Date wrappes around the java.util.Date. Because it handles the SQL-specific requirements.
· Sql date use when working with the databases.
· Also SQL date does not support timezone information. It depends on a JDBC driver.







