APIdia Launch Partner
Top Description Fields Constructors Methods
java.sql

public Class Time

extends Date
Class Inheritance
Imports
java.time.Instant, .LocalTime

A thin wrapper around the java.util.Date class that allows the JDBC API to identify this as an SQL TIME value. The Time class adds formatting and parsing operations to support the JDBC escape syntax for time values.

The date components should be set to the "zero epoch" value of January 1, 1970 and should not be accessed.

Since
1.1

Field Summary

Modifier and TypeField and Description
pack-priv static final long
serialVersionUID

Hides java.util.Date.serialVersionUID.

Private serial version unique ID to ensure serialization compatibility.

Constructor Summary

AccessConstructor and Description
public
Time(int
0 to 23
hour
,
int
0 to 59
minute
,
int
0 to 59
second
)
Deprecated since 1.2. Use the constructor that takes a milliseconds value in place of this constructor

Constructs a Time object initialized with the given values for the hour, minute, and second.

public
Time(long
milliseconds since January 1, 1970, 00:00:00 GMT; a negative number is milliseconds before January 1, 1970, 00:00:00 GMT
time
)

Constructs a Time object using a milliseconds time value.

Method Summary

Modifier and TypeMethod and Description
public int
getDate()

Overrides java.util.Date.getDate.

Deprecated since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a date component.

public int
getDay()

Overrides java.util.Date.getDay.

Deprecated since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a day component.

public int
getMonth()

Overrides java.util.Date.getMonth.

Deprecated since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a month component.

public int
getYear()

Overrides java.util.Date.getYear.

Deprecated since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a year component.

public void
setDate(int i)

Overrides java.util.Date.setDate.

Deprecated since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a date component.

public void
setMonth(int i)

Overrides java.util.Date.setMonth.

Deprecated since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a month component.

public void
setTime(long
milliseconds since January 1, 1970, 00:00:00 GMT; a negative number is milliseconds before January 1, 1970, 00:00:00 GMT
time
)

Overrides java.util.Date.setTime.

Sets a Time object using a milliseconds time value.

public void
setYear(int i)

Overrides java.util.Date.setYear.

Deprecated since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a year component.

public Instant
toInstant()

Overrides java.util.Date.toInstant.

This method always throws an UnsupportedOperationException and should not be used because SQL Time values do not have a date component.

public LocalTime

Returns:

a LocalTime object representing the same time value
toLocalTime
()

Converts this Time object to a LocalTime.

public String

Returns:

a String in hh:mm:ss format
toString
()

Overrides java.util.Date.toString.

Formats a time in JDBC time escape format.

public static Time

Returns:

a corresponding Time object
valueOf
(String
time in format "hh:mm:ss"
s
)

Converts a string in JDBC time escape format to a Time value.

public static Time

Returns:

a Time object
valueOf
(LocalTime
a LocalTime to convert
time
)

Obtains an instance of Time from a LocalTime object with the same hour, minute and second time value as the given LocalTime.

Inherited from java.util.Date:
afterbeforeclonecompareToequalsfromgetHoursgetMinutesgetSecondsgetTimegetTimezoneOffsethashCodeparsesetHourssetMinutessetSecondstoGMTStringtoLocaleStringUTC

Field Detail

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides java.util.Date.serialVersionUID.

Private serial version unique ID to ensure serialization compatibility.

Constructor Detail

Timeback to summary
public Time(int hour, int minute, int second)

Deprecated

since 1.2.

Use the constructor that takes a milliseconds value in place of this constructor

Constructs a Time object initialized with the given values for the hour, minute, and second. The driver sets the date components to January 1, 1970. Any method that attempts to access the date components of a Time object will throw a java.lang.IllegalArgumentException.

The result is undefined if a given argument is out of bounds.

Parameters
hour:int

0 to 23

minute:int

0 to 59

second:int

0 to 59

Annotations
@Deprecated
since:1.2
Timeback to summary
public Time(long time)

Constructs a Time object using a milliseconds time value.

Parameters
time:long

milliseconds since January 1, 1970, 00:00:00 GMT; a negative number is milliseconds before January 1, 1970, 00:00:00 GMT

Method Detail

getDateback to summary
public int getDate()

Overrides java.util.Date.getDate.

Deprecated

since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a date component.

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
setDate
getDayback to summary
public int getDay()

Overrides java.util.Date.getDay.

Deprecated

since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a day component.

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
getMonthback to summary
public int getMonth()

Overrides java.util.Date.getMonth.

Deprecated

since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a month component.

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
setMonth
getYearback to summary
public int getYear()

Overrides java.util.Date.getYear.

Deprecated

since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a year component.

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
setYear
setDateback to summary
public void setDate(int i)

Overrides java.util.Date.setDate.

Deprecated

since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a date component.

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
getDate
setMonthback to summary
public void setMonth(int i)

Overrides java.util.Date.setMonth.

Deprecated

since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a month component.

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
getMonth
setTimeback to summary
public void setTime(long time)

Overrides java.util.Date.setTime.

Sets a Time object using a milliseconds time value.

Parameters
time:long

milliseconds since January 1, 1970, 00:00:00 GMT; a negative number is milliseconds before January 1, 1970, 00:00:00 GMT

setYearback to summary
public void setYear(int i)

Overrides java.util.Date.setYear.

Deprecated

since 1.2.

This method is deprecated and should not be used because SQL TIME values do not have a year component.

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
getYear
toInstantback to summary
public Instant toInstant()

Overrides java.util.Date.toInstant.

This method always throws an UnsupportedOperationException and should not be used because SQL Time values do not have a date component.

Annotations
@Override
Exceptions
UnsupportedOperationException:
if this method is invoked
toLocalTimeback to summary
public LocalTime toLocalTime()

Converts this Time object to a LocalTime.

The conversion creates a LocalTime that represents the same hour, minute, and second time value as this Time. The nanosecond LocalTime field will be set to zero.

Returns:LocalTime

a LocalTime object representing the same time value

Annotations
@SuppressWarnings:deprecation
Since
1.8
toStringback to summary
public String toString()

Overrides java.util.Date.toString.

Formats a time in JDBC time escape format.

Returns:String

a String in hh:mm:ss format

Annotations
@SuppressWarnings:deprecation
valueOfback to summary
public static Time valueOf(String s)

Converts a string in JDBC time escape format to a Time value.

Parameters
s:String

time in format "hh:mm:ss"

Returns:Time

a corresponding Time object

valueOfback to summary
public static Time valueOf(LocalTime time)

Obtains an instance of Time from a LocalTime object with the same hour, minute and second time value as the given LocalTime. The nanosecond field from LocalTime is not part of the newly created Time object.

Parameters
time:LocalTime

a LocalTime to convert

Returns:Time

a Time object

Exceptions
NullPointerException:
if time is null
Since
1.8