Time class in Java SQL Last Updated : 26 Oct, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report Time class is a part of Java SQL package.This class is a thin wrapper around java.util.Date that allows JDBC API to identify this as a SQL TIME value. The initial value of time is set to 1st January, 1970. All values of time after that is positive and time before that is negative. Class Hierarchy: java.lang.Object ↳ java.util.Date ↳ java.sql.Time Constructors: Time(long t): creates a Time object using a milliseconds time value. Example to demonstrate how to create object of Time Class using Constructor: Java // Java program to demonstrate // Constructor of Time Class import java.sql.*; class GFG { public static void main(String args[]) { // time in milliseconds long milli = 123456789999l; // create a object java.sql.Time time = new java.sql.Time(milli); // display the time System.out.println("Time = " + time.toString()); } } Output: Time = 21:33:09 Methods: Method Explanation setTime(long t) sets the value of time using milliseconds toString() Formats a time in JDBC time escape format. valueOf(String s) Converts a string in JDBC time escape format to a Time value. setTime(long time): This method sets a Time object using a milliseconds time value. Syntax: public void setTime(long time) Parameters: This method accepts a mandatory parameter time which represents the time to be set in milliseconds since January 1, 1970, 00:00:00 GMT. valueOf(String s): This method converts a string in JDBC time escape format to a Time value. Syntax: public static Time valueOf(String s) Parameters: This method accepts a mandatory parameter s which represents the time in format "hh:mm:ss" Return Value: This method returns a corresponding Time object toString(): This method formats a time in JDBC time escape format. Syntax: public String toString() Return Value: This method returns a String in hh:mm:ss format. Program to demonstrate setTime(), valueOf() and toString() methods: Java // Java program to demonstrate // setTime(), valueOf() and toString() methods: import java.sql.*; class GFG { public static void main(String args[]) { // time in milliseconds long milli = 123456789999l; // create a object java.sql.Time time = new java.sql.Time(milli); // display the time System.out.println("Time = " + time.toString()); // ----- setTime() ----- // set another time // using setTime() method long milSec = 455415454l; time.setTime(milSec); // ----- toString() ----- // display the time // using toString() method System.out.println("New Time = " + time.toString()); // ----- valueOf() ----- // using valueOf() method System.out.println("Value of 00:05:29 = " + Time.valueOf("00:05:29")); } } Output: Time = 21:33:09 New Time = 06:30:15 Value of 00:05:29 = 00:05:29 Reference: https://docs.oracle.com/javase/7/docs/api/java/sql/Time.html Comment More infoAdvertise with us Next Article java.time.LocalTime Class in Java A andrew1234 Follow Improve Article Tags : Java Java 8 Practice Tags : Java Similar Reads java.time.LocalTime Class in Java Java is the most popular programming language and widely used programming language. Java is used in all kinds of applications like mobile applications, desktop applications, web applications. As in Java, java.time.LocalTime class represents time, which is viewed as hour-minute-second. This class is 5 min read java.time.LocalDate Class in Java Java is the most popular programming language and widely used programming language. Java is used in all kind of application like as mobile application, desktop application, web application. In this Java java.time.LocalDate class is imported which represents to display the current date. java.time: It 4 min read java.time.Period Class in Java The Period Class in Java class obtains a quantity or amount of time in terms of years, months and days. The time obtained is a date-based amount of time in the ISO-8601 calendar system, such as '4 years, 5 months, and 6 days. The units which are supported for a period are YEARS, MONTHS, and days. Al 5 min read java.time.Instant Class in Java In Java language, the Instant Class is used to represent the specific time instant on the current timeline. The Instant Class extends the Object Class and implements the Comparable interface. Declaration of the Instant Class public final class Instant extends Object implements Temporal, TemporalAdju 4 min read java.time.OffsetTime Class in Java Java OffsetTime class is an immutable date-time object that represents a time, often viewed as hour-minute-second offset. OffsetTime class represents a time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 18:30:45+08:00, often viewed as an hour-minute-second-offset. This c 7 min read java.time.Duration Class in Java Duration is the value-based Class present in the Java time library. It's used to get time-based amount of time. This class is immutable and thread-safe. This article describes all the methods present in this class and some basic examples using class methods. This class implements Serializable, Comp 4 min read Like