Serializable
, Cloneable
, Comparable<Date>
public class Time extends Date
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.
Constructor | Description |
---|---|
Time |
Deprecated. Use the constructor that takes a milliseconds value in place of this constructor |
Time |
Constructs a Time object using a milliseconds time value. |
Modifier and Type | Method | Description |
---|---|---|
int |
getDate() |
Deprecated. |
int |
getDay() |
Deprecated. |
int |
getMonth() |
Deprecated. |
int |
getYear() |
Deprecated. |
void |
setDate |
Deprecated. |
void |
setMonth |
Deprecated. |
void |
setTime |
Sets a Time object using a milliseconds time value. |
void |
setYear |
Deprecated. |
Instant |
toInstant() |
This method always throws an UnsupportedOperationException and should not be used because SQL Time values do not have a date component. |
LocalTime |
toLocalTime() |
Converts this Time object to a LocalTime . |
String |
toString() |
Formats a time in JDBC time escape format. |
static Time |
valueOf |
Converts a string in JDBC time escape format to a Time value. |
static Time |
valueOf |
Obtains an instance of Time from a LocalTime object with the same hour, minute and second time value as the given LocalTime . |
after, before, clone, compareTo, equals, from, getHours, getMinutes, getSeconds, getTime, getTimezoneOffset, hashCode, parse, setHours, setMinutes, setSeconds, toGMTString, toLocaleString, UTC
@Deprecated(since="1.2") public Time(int hour, int minute, int second)
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.
hour
- 0 to 23minute
- 0 to 59second
- 0 to 59public Time(long time)
Time
object using a milliseconds time value.time
- milliseconds since January 1, 1970, 00:00:00 GMT; a negative number is milliseconds before January 1, 1970, 00:00:00 GMTpublic void setTime(long time)
Time
object using a milliseconds time value.public static Time valueOf(String s)
Time
value.s
- time in format "hh:mm:ss"Time
objectpublic String toString()
@Deprecated(since="1.2") public int getYear()
TIME
values do not have a year component.getYear
in class Date
IllegalArgumentException
- if this method is invoked@Deprecated(since="1.2") public int getMonth()
TIME
values do not have a month component.getMonth
in class Date
IllegalArgumentException
- if this method is invoked@Deprecated(since="1.2") public int getDay()
TIME
values do not have a day component.getDay
in class Date
IllegalArgumentException
- if this method is invoked@Deprecated(since="1.2") public int getDate()
TIME
values do not have a date component.getDate
in class Date
IllegalArgumentException
- if this method is invoked@Deprecated(since="1.2") public void setYear(int i)
TIME
values do not have a year component.setYear
in class Date
i
- the year value.IllegalArgumentException
- if this method is invoked@Deprecated(since="1.2") public void setMonth(int i)
TIME
values do not have a month component.setMonth
in class Date
i
- the month value between 0-11.IllegalArgumentException
- if this method is invoked@Deprecated(since="1.2") public void setDate(int i)
TIME
values do not have a date component.setDate
in class Date
i
- the day of the month value between 1-31.IllegalArgumentException
- if this method is invokedpublic static Time valueOf(LocalTime time)
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.time
- a LocalTime
to convertTime
objectNullPointerException
- if time
is nullpublic LocalTime toLocalTime()
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.
LocalTime
object representing the same time valuepublic Instant toInstant()
Time
values do not have a date component.toInstant
in class Date
Date
objectUnsupportedOperationException
- if this method is invoked
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.sql/java/sql/Time.html