Time Class Operation in Java
The Java SQL package includes the time class. This class is merely a lightweight wrapper for java. util. THANKS TO THE recognize BC API can recognize this as a SQL TIME value. Time is set to 1970 on January 1st as its starting value. Time after that has all positive values, whereas time before has negative ones.

Constructors:
By Time(long t) constructs a Time object by utilizing a milliseconds time valueava Program
Timeclass1.java
// Java program to explain the constructor of Time Class
import java.sql.* ;
class Timeclass1{
public static void main (String s [ ])
{
// milliseconds
long m = 123456789999l;
// Object creation for the class
java.sql.Time t1 = new java.sql.Time(m) ;
// printing the time
System.out.println ( " Time = " + t1.toString( ) ) ;
}
}
Output

Methods
Method | Explanation |
setTime(long t) | The millisecond value of time is set using the function . |
toString() | JDBC time escape format is applied to a time using the action toString(). |
valueOf() | A string in JDBC time escape format is converted to a Time value via valueOf(String s). |
setTime() | Sets a Time object with a milliseconds time value using the settime ng time) function. Syntax public void setTime(long time) The obligatory parameter time, which indicates the time to be set in milliseconds since January 1, 1970, 00:00:00 GMT, is accepted by this method. |
valueOf() | This method, valueOf(String s), turns a string in JDBC time escape format into a Time value. Syntax: public static Value of time (String s) The obligatory parameter s, which represents the time in the format "hh:mm:ss," is accepted by this method. Return Value: An appropriate Time object is returned by this method. |
toString () | JDBC time escape format is used in the function toString() method to format a time. Syntax public String to String () Return Value: The hh:mm:ss formatted String is returned by this procedure. |
Java program
import java.sql.*;
class Timeclass2 {
public static void main(String args[])
{
long m = 123413789999l;
// create an object
java. sql. Time t = new java. sql. Time ( m ) ;
// display the time
System . out. println ( " Time = " + t . toString ( ) ) ;
long ms = 476415454l;
t . setTime ( ms ) ;
System . out. println ( " New Time = " + t . toString ( ) ) ;
System . out. println ( " Value of 00:04:29 = " + Time.valueOf ("00:04:29" ) ) ;
}
}
Before the release of Java 8, the main classes were:
Java. Lang.
System: The current time in milliseconds is returned by the class's currentTimeMillis() method. From January 1st, 1970, it displays the current date and time in milliseconds.
java.util.Date
Date: It is used to display a precise moment in milliseconds.
Java 8 adds a new Date Time API.
The new date API overcomes the shortcomings of the old classes listed above.
java.time.LocalDate
LocalDate: It is useful for displaying dates without times because it represents a year, month, and day on the ISO calendar. It can be used to describe information with a single date, such as birth date or wedding date.
java.time.LocalTime
LocalTime: It simply deals with time. It helps display the time of day based on humans, such as movie times or the hours that the nearby library is open and closed.
java.time.LocalDateTime
LocalDateTime: It manages date and time without considering a time zone. It is the result of combining LocalDate and LocalTime.
java.time.ZonedDateTime
It combines the LocalDateTime class with the zone information found in ZoneId to create ZonedDateTime.
java.util.Calendar
Calendar: This abstract class offers techniques to change the values of the calendar fields and convert them between instances.
Java.text.SimpleDateFormat
SimpleDateFormat: This class formats and parses dates according to the user- or predefined-pattern definitions.
java.util.TimeZone
TimeZone: It calculates daylight savings time and represents a time zone offset.
java.time.OffsetDateTime
Without a time zone ID, OffsetDateTime manages dates and times with an appropriate time zone offset from Greenwich/UTC.
java.time.Clock
Clock: It gives users access to the time, date, and instant in any selected time zone. This capability enables us to test your code for additional time zones or by utilizing a fixed clock, where time does not change, even though the Clock class is optional.