Package oracle.sql
Class TIMESTAMP
- java.lang.Object
-
- oracle.sql.Datum
-
- oracle.sql.TIMESTAMP
-
- All Implemented Interfaces:
java.io.Serializable
,oracle.jdbc.internal.OracleTimestamp
public class TIMESTAMP extends Datum implements java.io.Serializable, oracle.jdbc.internal.OracleTimestamp
TIMESTAMP Class
TheTIMESTAMP
class provides conversions between the Oracle Date (ldx_t) data type and Java classesjava.sql.Date
,java.sql.Time
,java.sql.Timestamp
The internal data for this object is stored as a eleven byte array in the super class' storage area. The bytes are arranged as follows:
Byte Represents 0 Century (119 for 1990) 1 Decade (190 for 1990) 2 Month 3 Day 4 Hour 5 Minute 6 Seconds 7 Nanoseconds 8 Nanoseconds 9 Nanoseconds 10 Nanoseconds
Static methods are used for conversions.
- Since:
- release specific (what release of product did this appear in)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
SIZE_DATE
static int
SIZE_TIMESTAMP
static int
SIZE_TIMESTAMP_NOFRAC
-
Fields inherited from class oracle.sql.Datum
ojiOracleDatumWithConnection, targetDatum
-
-
Constructor Summary
Constructors Constructor Description TIMESTAMP()
Constructs a TIMESTAMP object initialized to 1/1/1970.TIMESTAMP(byte[] timestamp)
Create an Oracle TIMESTAMP object represented by the given Oracle TimestampTIMESTAMP(java.lang.String str)
Create a TIMESTAMP object given a Java String object.TIMESTAMP(java.sql.Date date)
Create an Oracle TIMESTAMP object represented by the Java DateTIMESTAMP(java.sql.Time time)
Create an Oracle TIMESTAMP object represented by the given Java TimeTIMESTAMP(java.sql.Timestamp timestamp)
Create an Oracle TIMESTAMP object represented by the Java TimestampTIMESTAMP(java.sql.Timestamp timestamp, java.util.Calendar cal)
Create an Oracle TIMESTAMP object represented by the Java Timestamp and CalendarTIMESTAMP(java.time.LocalDate ld)
Create a TIMESTAMP object given a Java LocalDateTIMESTAMP(java.time.LocalDateTime ldt)
Create a TIMESTAMP object given a Java LocalDateTimeTIMESTAMP(java.time.LocalTime lt)
Create a TIMESTAMP object given a Java LocalTimeTIMESTAMP(java.time.OffsetDateTime odt)
Create a TIMESTAMP object given a Java OffsetDateTimeTIMESTAMP(java.time.OffsetTime ot)
Create a TIMESTAMP object given a Java OffsetTimeTIMESTAMP(java.time.ZonedDateTime zdt)
Create a TIMESTAMP object given a Java ZonedDateTimeTIMESTAMP(DATE date)
Create an Oracle TIMESTAMP object represented by the Oracle DATE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.sql.Date
dateValue()
Calls toDate to convert internal Oracle TIMESTAMP to a Java Date.static int
getJavaYear(int cent, int decade)
static int
getOracleYear(int jYear)
static int
getOracleYear(java.util.Calendar cal)
boolean
isConvertibleTo(java.lang.Class<?> cls)
Determines if the object can be converted to a particular classjava.time.LocalDateTime
localDateTimeValue()
Converts TIMESTAMP to LocalDateTime.java.time.LocalDate
localDateValue()
Converts TIMESTAMP to LocalDate.java.time.LocalTime
localTimeValue()
Converts TIMESTAMP to LocalTime.java.lang.Object
makeJdbcArray(int arraySize)
Returns a JDBC array representation of the datumstatic TIMESTAMP
of(java.time.LocalDate ld)
Creates TIMESTAMP from the LocalDate.static TIMESTAMP
of(java.time.LocalDateTime ldt)
Creates TIMESTAMP from the LocalDateTime.static TIMESTAMP
of(java.time.LocalTime lt)
Creates TIMESTAMP from the LocalTime.static TIMESTAMP
of(java.time.OffsetDateTime odt)
Create a TIMESTAMP object given a Java OffsetDateTimestatic TIMESTAMP
of(java.time.OffsetTime ot)
Create a TIMESTAMP object given a Java OffsetTimestatic TIMESTAMP
of(java.time.ZonedDateTime zdt)
Create a TIMESTAMP object given a Java ZonedDateTimejava.lang.String
stringValue()
Calls toString to convert internal Oracle TIMESTAMP to a Java String.java.sql.Timestamp
timestampValue()
Calls toTimestamp to convert internal Oracle TIMESTAMP to a Java Timestamp.java.sql.Timestamp
timestampValue(java.util.Calendar cal)
Calls toTimestamp to convert internal Oracle TIMESTAMP and Calendar to a Java Timestamp.java.sql.Time
timeValue()
Calls toTime to convert internal Oracle Date to a Java Time.static TIMESTAMP
TimeZoneConvert(java.sql.Connection conn, TIMESTAMP tstamp, java.util.TimeZone tz1, java.util.TimeZone tz2)
Converts the TIMESTAMP object from one timezone to the otherbyte[]
toBytes()
Convert Oracle TIMESTAMP object into a byte arraystatic byte[]
toBytes(java.lang.String str)
Convert Java String to Oracle TIMESTAMP.static byte[]
toBytes(java.sql.Date date)
Convert Java Date to Oracle TIMESTAMP.static byte[]
toBytes(java.sql.Time time)
Convert Java Time to Oracle TIMESTAMP.static byte[]
toBytes(java.sql.Timestamp timestamp)
Convert Java Timestamp to Oracle TIMESTAMPstatic byte[]
toBytes(java.sql.Timestamp timestamp, java.util.Calendar cal)
Convert Java Timestamp and Java Calendar to Oracle TIMESTAMPstatic byte[]
toBytes(java.time.LocalDate ld)
Convert Java LocalDate to Oracle TIMESTAMPstatic byte[]
toBytes(java.time.LocalDateTime ldt)
Convert Java LocalDateTime to Oracle TIMESTAMPstatic byte[]
toBytes(java.time.LocalTime lt)
Convert Java LocalTime to Oracle TIMESTAMPstatic byte[]
toBytes(java.time.OffsetDateTime odt)
Convert Java OffsetDateTime to Oracle TIMESTAMPstatic byte[]
toBytes(java.time.OffsetTime ot)
Convert Java OffsetTime to Oracle TIMESTAMPstatic byte[]
toBytes(java.time.ZonedDateTime zdt)
Convert Java ZonedDateTime to Oracle TIMESTAMPstatic byte[]
toBytes(DATE date)
Convert Oracle DATE to Oracle TIMESTAMPstatic java.sql.Date
toDate(byte[] timestamp)
Convert a byte array representing a TIMESTAMP object to a Java Date Objectstatic DATE
toDATE(byte[] timestamp)
Convert a byte array representing a TIMESTAMP object to a Oracle DATE Objectjava.lang.Object
toJdbc()
Returns the JDBC representation of the datum objectjava.time.LocalDate
toLocalDate()
Converts TIMESTAMP to LocalDate.static java.time.LocalDate
toLocalDate(byte[] timestamp)
Convert a byte array representing a TIMESTAMP object to a Java LocalDatejava.time.LocalDateTime
toLocalDateTime()
Converts TIMESTAMP to LocalDateTime.static java.time.LocalDateTime
toLocalDateTime(byte[] timestamp)
Convert a byte array representing a TIMESTAMP object to a Java LocalDateTimejava.time.LocalTime
toLocalTime()
Converts TIMESTAMP to LocalTime.static java.time.LocalTime
toLocalTime(byte[] timestamp)
Convert a byte array representing a TIMESTAMP object to a Java LocalTimejava.lang.String
toString()
static java.lang.String
toString(byte[] bytes)
Converts a TIMESTAMP to a stringstatic java.sql.Time
toTime(byte[] timestamp)
Convert a byte array representing a TIMESTAMP object to a Java Time Objectstatic java.sql.Timestamp
toTimestamp(byte[] timestamp)
Convert a byte array representing a TIMESTAMP object to a Java Timestamp Objectstatic java.sql.Timestamp
toTimestamp(byte[] timestamp, java.util.Calendar cal)
Convert a byte array representing a TIMESTAMP object to a Java Timestamp Object given Calendar object-
Methods inherited from class oracle.sql.Datum
asciiStreamValue, bigDecimalValue, binaryStreamValue, booleanValue, bytesEqual, bytesHashCode, byteValue, characterStreamValue, compareBytes, doubleValue, equals, floatValue, getBytes, getConnectionDuringExceptionHandling, getLength, getStream, intValue, isNull, longValue, setBytes, setShareBytes, shareBytes, stringValue, timeValue, toClass
-
-
-
-
Field Detail
-
SIZE_DATE
public static final int SIZE_DATE
- See Also:
- Constant Field Values
-
SIZE_TIMESTAMP
public static final int SIZE_TIMESTAMP
- See Also:
- Constant Field Values
-
SIZE_TIMESTAMP_NOFRAC
public static final int SIZE_TIMESTAMP_NOFRAC
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TIMESTAMP
public TIMESTAMP()
Constructs a TIMESTAMP object initialized to 1/1/1970.
-
TIMESTAMP
public TIMESTAMP(byte[] timestamp)
Create an Oracle TIMESTAMP object represented by the given Oracle Timestamp- Parameters:
timestamp
- Oracle TIMESTAMP
-
TIMESTAMP
public TIMESTAMP(java.sql.Time time)
Create an Oracle TIMESTAMP object represented by the given Java Time- Parameters:
time
- Java Time object
-
TIMESTAMP
public TIMESTAMP(java.sql.Date date)
Create an Oracle TIMESTAMP object represented by the Java Date- Parameters:
date
- Java Date object
-
TIMESTAMP
public TIMESTAMP(java.sql.Timestamp timestamp)
Create an Oracle TIMESTAMP object represented by the Java Timestamp- Parameters:
timestamp
- Java Timestamp object
-
TIMESTAMP
public TIMESTAMP(java.sql.Timestamp timestamp, java.util.Calendar cal)
Create an Oracle TIMESTAMP object represented by the Java Timestamp and Calendar- Parameters:
timestamp
- Java Timestamp objectcal
- Java Util Calendar object
-
TIMESTAMP
public TIMESTAMP(DATE date)
Create an Oracle TIMESTAMP object represented by the Oracle DATE- Parameters:
date
- Oracle DATE object
-
TIMESTAMP
public TIMESTAMP(java.lang.String str)
Create a TIMESTAMP object given a Java String object.- Parameters:
str
- Java String object
-
TIMESTAMP
public TIMESTAMP(java.time.OffsetDateTime odt)
Create a TIMESTAMP object given a Java OffsetDateTime- Parameters:
odt
- OffsetDateTime object
-
TIMESTAMP
public TIMESTAMP(java.time.ZonedDateTime zdt)
Create a TIMESTAMP object given a Java ZonedDateTime- Parameters:
zdt
- ZonedDateTime object
-
TIMESTAMP
public TIMESTAMP(java.time.LocalDateTime ldt)
Create a TIMESTAMP object given a Java LocalDateTime- Parameters:
zdt
- LocalDateTime object
-
TIMESTAMP
public TIMESTAMP(java.time.LocalTime lt)
Create a TIMESTAMP object given a Java LocalTime- Parameters:
lt
- LocalTime object
-
TIMESTAMP
public TIMESTAMP(java.time.LocalDate ld)
Create a TIMESTAMP object given a Java LocalDate- Parameters:
ld
- LocalDate object
-
TIMESTAMP
public TIMESTAMP(java.time.OffsetTime ot)
Create a TIMESTAMP object given a Java OffsetTime- Parameters:
ot
- OffsetTime object
-
-
Method Detail
-
toDate
public static java.sql.Date toDate(byte[] timestamp) throws java.sql.SQLException
Convert a byte array representing a TIMESTAMP object to a Java Date Object- Parameters:
timestamp
- Oracle TIMESTAMP object- Returns:
- the Java date object represented by Oracle TIMESTAMP object
- Throws:
java.sql.SQLException
-
toTime
public static java.sql.Time toTime(byte[] timestamp) throws java.sql.SQLException
Convert a byte array representing a TIMESTAMP object to a Java Time Object- Parameters:
timestamp
- Oracle TIMESTAMP object- Returns:
- the java.sql.Time object represented by Oracle TIMESTAMP object. Only the hour, minute and seconds are contained in the java.sql.Time object that is returned and hence callers should not attempt to access the date component of the returned object.
- Throws:
java.sql.SQLException
-
toTimestamp
public static java.sql.Timestamp toTimestamp(byte[] timestamp) throws java.sql.SQLException
Convert a byte array representing a TIMESTAMP object to a Java Timestamp Object- Parameters:
timestamp
- Oracle TIMESTAMP object- Returns:
- the Java timestamp object represented by Oracle TIMESTAMP object
- Throws:
java.sql.SQLException
-
toTimestamp
public static java.sql.Timestamp toTimestamp(byte[] timestamp, java.util.Calendar cal) throws java.sql.SQLException
Convert a byte array representing a TIMESTAMP object to a Java Timestamp Object given Calendar object- Parameters:
timestamp
- Oracle TIMESTAMP object to be convertedcal
- java.utl.Calendar object- Returns:
- the java.sql.Timestamp object represented by the Oracle TIMESTAMP object.
- Throws:
java.sql.SQLException
-
toDATE
public static DATE toDATE(byte[] timestamp) throws java.sql.SQLException
Convert a byte array representing a TIMESTAMP object to a Oracle DATE Object- Parameters:
timestamp
- Oracle TIMESTAMP object- Returns:
- the oracle DATE object represented by Oracle TIMESTAMP object
- Throws:
java.sql.SQLException
-
timestampValue
public java.sql.Timestamp timestampValue() throws java.sql.SQLException
Calls toTimestamp to convert internal Oracle TIMESTAMP to a Java Timestamp.- Overrides:
timestampValue
in classDatum
- Returns:
- a Java Timestamp value
- Throws:
java.sql.SQLException
-
timestampValue
public java.sql.Timestamp timestampValue(java.util.Calendar cal) throws java.sql.SQLException
Calls toTimestamp to convert internal Oracle TIMESTAMP and Calendar to a Java Timestamp.- Overrides:
timestampValue
in classDatum
- Returns:
- a Java Timestamp value
- Throws:
java.sql.SQLException
-
toString
public static java.lang.String toString(byte[] bytes)
Converts a TIMESTAMP to a string- Parameters:
date
- a byte array- Returns:
- String representing the date
-
toBytes
public byte[] toBytes()
Convert Oracle TIMESTAMP object into a byte array- Specified by:
toBytes
in interfaceoracle.jdbc.internal.OracleTimestamp
- Returns:
- the byte array stored in the TIMESTAMP object
-
toBytes
public static byte[] toBytes(java.sql.Time time)
Convert Java Time to Oracle TIMESTAMP.- Parameters:
time
- java.sql.Time object to be converted.- Returns:
- the byte array representing the java Time.
-
toBytes
public static byte[] toBytes(java.sql.Date date)
Convert Java Date to Oracle TIMESTAMP.- Parameters:
date
- java.sql.Date object to be converted.- Returns:
- the byte array representing the java Date.
-
toBytes
public static byte[] toBytes(java.sql.Timestamp timestamp)
Convert Java Timestamp to Oracle TIMESTAMP- Parameters:
Timestamp
- java.sql.Timestamp object to be converted.- Returns:
- the byte array representing the java timestamp.
-
toBytes
public static byte[] toBytes(java.sql.Timestamp timestamp, java.util.Calendar cal)
Convert Java Timestamp and Java Calendar to Oracle TIMESTAMP- Parameters:
Timestamp
- java.sql.Timestamp object to be converted.Calendar
- java.util.Calendar object to be converted.- Returns:
- the byte array representing the java timestamp.
-
toBytes
public static byte[] toBytes(DATE date)
Convert Oracle DATE to Oracle TIMESTAMP- Parameters:
date
- oracle.sql.Timestamp object to be converted.- Returns:
- the byte array representing the oracle DATE.
-
toBytes
public static byte[] toBytes(java.lang.String str)
Convert Java String to Oracle TIMESTAMP.- Parameters:
str
- java.lang.String object to be converted.- Returns:
- the byte array representing the input string.
-
toJdbc
public java.lang.Object toJdbc() throws java.sql.SQLException
Returns the JDBC representation of the datum object
-
makeJdbcArray
public java.lang.Object makeJdbcArray(int arraySize)
Returns a JDBC array representation of the datum- Specified by:
makeJdbcArray
in classDatum
- Parameters:
arraySize
- size of the array- Returns:
- an object containing the JDBC array value
-
isConvertibleTo
public boolean isConvertibleTo(java.lang.Class<?> cls)
Determines if the object can be converted to a particular class- Specified by:
isConvertibleTo
in classDatum
- Parameters:
cls
- Class to convert to- Returns:
- true, if conversion to cls is permitted false, if conversion to cls is not permitted
-
TimeZoneConvert
public static TIMESTAMP TimeZoneConvert(java.sql.Connection conn, TIMESTAMP tstamp, java.util.TimeZone tz1, java.util.TimeZone tz2) throws java.sql.SQLException
Converts the TIMESTAMP object from one timezone to the other- Parameters:
conn
- Java Connection object tstamp TIMESTAMP object to be converted tz1 Source timezone tz2 Destination timezone- Returns:
- TIMESTAMP object in the destination timezone
- Throws:
java.sql.SQLException
-
stringValue
public java.lang.String stringValue()
Calls toString to convert internal Oracle TIMESTAMP to a Java String.- Overrides:
stringValue
in classDatum
- Returns:
- a Java String value
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getOracleYear
public static int getOracleYear(java.util.Calendar cal)
-
getOracleYear
public static int getOracleYear(int jYear)
-
dateValue
public java.sql.Date dateValue() throws java.sql.SQLException
Calls toDate to convert internal Oracle TIMESTAMP to a Java Date.
-
timeValue
public java.sql.Time timeValue() throws java.sql.SQLException
Calls toTime to convert internal Oracle Date to a Java Time.
-
getJavaYear
public static int getJavaYear(int cent, int decade)
-
of
public static TIMESTAMP of(java.time.LocalDateTime ldt) throws java.sql.SQLException
Creates TIMESTAMP from the LocalDateTime.- Parameters:
ldt
- LocalDateTime object- Returns:
- TIMESTAMP object
- Throws:
java.sql.SQLException
-
toLocalDateTime
public java.time.LocalDateTime toLocalDateTime() throws java.sql.SQLException
Converts TIMESTAMP to LocalDateTime.- Returns:
- LocalDateTime object.
- Throws:
java.sql.SQLException
-
localDateTimeValue
public java.time.LocalDateTime localDateTimeValue() throws java.sql.SQLException
Converts TIMESTAMP to LocalDateTime.- Returns:
- LocalDateTime object.
- Throws:
java.sql.SQLException
-
of
public static TIMESTAMP of(java.time.OffsetDateTime odt)
Create a TIMESTAMP object given a Java OffsetDateTime- Parameters:
odt
- OffsetDateTime object
-
toLocalDateTime
public static java.time.LocalDateTime toLocalDateTime(byte[] timestamp) throws java.sql.SQLException
Convert a byte array representing a TIMESTAMP object to a Java LocalDateTime- Parameters:
timestamp
- Oracle TIMESTAMP object to be converted- Returns:
- the java.time.LocalDateTime object represented by the Oracle TIMESTAMP object.
- Throws:
java.sql.SQLException
-
toLocalTime
public static java.time.LocalTime toLocalTime(byte[] timestamp) throws java.sql.SQLException
Convert a byte array representing a TIMESTAMP object to a Java LocalTime- Parameters:
timestamp
- Oracle TIMESTAMP object to be converted- Returns:
- the java.time.LocalTime object represented by the Oracle TIMESTAMP object.
- Throws:
java.sql.SQLException
-
toLocalDate
public static java.time.LocalDate toLocalDate(byte[] timestamp) throws java.sql.SQLException
Convert a byte array representing a TIMESTAMP object to a Java LocalDate- Parameters:
timestamp
- Oracle TIMESTAMP object to be converted- Returns:
- the java.time.LocalDate object represented by the Oracle TIMESTAMP object.
- Throws:
java.sql.SQLException
-
of
public static TIMESTAMP of(java.time.ZonedDateTime zdt)
Create a TIMESTAMP object given a Java ZonedDateTime- Parameters:
zdt
- ZonedDateTime object
-
of
public static TIMESTAMP of(java.time.OffsetTime ot)
Create a TIMESTAMP object given a Java OffsetTime- Parameters:
ot
- OffsetTime object
-
of
public static TIMESTAMP of(java.time.LocalTime lt) throws java.sql.SQLException
Creates TIMESTAMP from the LocalTime.- Parameters:
lt
- LocalTime object- Returns:
- TIMESTAMP object
- Throws:
java.sql.SQLException
-
toLocalTime
public java.time.LocalTime toLocalTime() throws java.sql.SQLException
Converts TIMESTAMP to LocalTime.- Returns:
- LocalTime object.
- Throws:
java.sql.SQLException
-
localTimeValue
public java.time.LocalTime localTimeValue() throws java.sql.SQLException
Converts TIMESTAMP to LocalTime.- Returns:
- LocalTime object.
- Throws:
java.sql.SQLException
-
of
public static TIMESTAMP of(java.time.LocalDate ld) throws java.sql.SQLException
Creates TIMESTAMP from the LocalDate.- Parameters:
ld
- LocalDate object- Returns:
- TIMESTAMP object
- Throws:
java.sql.SQLException
-
toLocalDate
public java.time.LocalDate toLocalDate() throws java.sql.SQLException
Converts TIMESTAMP to LocalDate.- Returns:
- LocalDate object.
- Throws:
java.sql.SQLException
-
localDateValue
public java.time.LocalDate localDateValue() throws java.sql.SQLException
Converts TIMESTAMP to LocalDate.- Returns:
- LocalTime object.
- Throws:
java.sql.SQLException
-
toBytes
public static byte[] toBytes(java.time.OffsetDateTime odt)
Convert Java OffsetDateTime to Oracle TIMESTAMP- Parameters:
odt
- OffsetDateTime object- Returns:
- the byte array representing the java OffsetDateTime.
-
toBytes
public static byte[] toBytes(java.time.ZonedDateTime zdt)
Convert Java ZonedDateTime to Oracle TIMESTAMP- Parameters:
zdt
- ZonedDateTime object- Returns:
- the byte array representing the java ZonedDateTime.
-
toBytes
public static byte[] toBytes(java.time.OffsetTime ot)
Convert Java OffsetTime to Oracle TIMESTAMP- Parameters:
ot
- OffsetTime object- Returns:
- the byte array representing the java OffsetTime.
-
toBytes
public static byte[] toBytes(java.time.LocalDate ld)
Convert Java LocalDate to Oracle TIMESTAMP- Parameters:
ld
- LocalDate object- Returns:
- the byte array representing the java LocalDate.
-
toBytes
public static byte[] toBytes(java.time.LocalDateTime ldt)
Convert Java LocalDateTime to Oracle TIMESTAMP- Parameters:
ldt
- LocalDateTime object- Returns:
- the byte array representing the java LocalDateTime.
-
toBytes
public static byte[] toBytes(java.time.LocalTime lt)
Convert Java LocalTime to Oracle TIMESTAMP- Parameters:
lt
- LocalTime object- Returns:
- the byte array representing the java LocalTime.
-
-