Package oracle.sql

Class TIMESTAMP

java.lang.Object
oracle.sql.Datum
oracle.sql.TIMESTAMP
All Implemented Interfaces:
Serializable, oracle.jdbc.internal.OracleTimestamp

public class TIMESTAMP extends Datum implements Serializable, oracle.jdbc.internal.OracleTimestamp
TIMESTAMP Class


The TIMESTAMP class provides conversions between the Oracle Date (ldx_t) data type and Java classes java.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:
  • Field Details

  • Constructor Details

    • 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(Time time)
      Create an Oracle TIMESTAMP object represented by the given Java Time
      Parameters:
      time - Java Time object
    • TIMESTAMP

      public TIMESTAMP(Date date)
      Create an Oracle TIMESTAMP object represented by the Java Date
      Parameters:
      date - Java Date object
    • TIMESTAMP

      public TIMESTAMP(Timestamp timestamp)
      Create an Oracle TIMESTAMP object represented by the Java Timestamp
      Parameters:
      timestamp - Java Timestamp object
    • TIMESTAMP

      public TIMESTAMP(Timestamp timestamp, Calendar cal)
      Create an Oracle TIMESTAMP object represented by the Java Timestamp and Calendar
      Parameters:
      timestamp - Java Timestamp object
      cal - 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(String str)
      Create a TIMESTAMP object given a Java String object.
      Parameters:
      str - Java String object
    • TIMESTAMP

      public TIMESTAMP(OffsetDateTime odt)
      Create a TIMESTAMP object given a Java OffsetDateTime
      Parameters:
      odt - OffsetDateTime object
    • TIMESTAMP

      public TIMESTAMP(ZonedDateTime zdt)
      Create a TIMESTAMP object given a Java ZonedDateTime
      Parameters:
      zdt - ZonedDateTime object
    • TIMESTAMP

      public TIMESTAMP(LocalDateTime ldt)
      Create a TIMESTAMP object given a Java LocalDateTime
      Parameters:
      zdt - LocalDateTime object
    • TIMESTAMP

      public TIMESTAMP(LocalTime lt)
      Create a TIMESTAMP object given a Java LocalTime
      Parameters:
      lt - LocalTime object
    • TIMESTAMP

      public TIMESTAMP(LocalDate ld)
      Create a TIMESTAMP object given a Java LocalDate
      Parameters:
      ld - LocalDate object
    • TIMESTAMP

      public TIMESTAMP(OffsetTime ot)
      Create a TIMESTAMP object given a Java OffsetTime
      Parameters:
      ot - OffsetTime object
  • Method Details

    • toDate

      public static Date toDate(byte[] timestamp) throws 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:
      SQLException
    • toTime

      public static Time toTime(byte[] timestamp) throws 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:
      SQLException
    • toTimestamp

      public static Timestamp toTimestamp(byte[] timestamp) throws 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:
      SQLException
    • toTimestamp

      public static Timestamp toTimestamp(byte[] timestamp, Calendar cal) throws SQLException
      Convert a byte array representing a TIMESTAMP object to a Java Timestamp Object given Calendar object
      Parameters:
      timestamp - Oracle TIMESTAMP object to be converted
      cal - java.utl.Calendar object
      Returns:
      the java.sql.Timestamp object represented by the Oracle TIMESTAMP object.
      Throws:
      SQLException
    • toDATE

      public static DATE toDATE(byte[] timestamp) throws 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:
      SQLException
    • timestampValue

      public Timestamp timestampValue() throws SQLException
      Calls toTimestamp to convert internal Oracle TIMESTAMP to a Java Timestamp.
      Overrides:
      timestampValue in class Datum
      Returns:
      a Java Timestamp value
      Throws:
      SQLException
    • timestampValue

      public Timestamp timestampValue(Calendar cal) throws SQLException
      Calls toTimestamp to convert internal Oracle TIMESTAMP and Calendar to a Java Timestamp.
      Overrides:
      timestampValue in class Datum
      Returns:
      a Java Timestamp value
      Throws:
      SQLException
    • toString

      public static 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 interface oracle.jdbc.internal.OracleTimestamp
      Returns:
      the byte array stored in the TIMESTAMP object
    • toBytes

      public static byte[] toBytes(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(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(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(Timestamp timestamp, 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(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 Object toJdbc() throws SQLException
      Returns the JDBC representation of the datum object
      Specified by:
      toJdbc in class Datum
      Returns:
      an object containing the JDBC value
      Throws:
      SQLException - if conversion to JDBC representation results in an error
    • makeJdbcArray

      public Object makeJdbcArray(int arraySize)
      Returns a JDBC array representation of the datum
      Specified by:
      makeJdbcArray in class Datum
      Parameters:
      arraySize - size of the array
      Returns:
      an object containing the JDBC array value
    • isConvertibleTo

      public boolean isConvertibleTo(Class<?> cls)
      Determines if the object can be converted to a particular class
      Specified by:
      isConvertibleTo in class Datum
      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(Connection conn, TIMESTAMP tstamp, TimeZone tz1, TimeZone tz2) throws 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:
      SQLException
    • stringValue

      public String stringValue()
      Calls toString to convert internal Oracle TIMESTAMP to a Java String.
      Overrides:
      stringValue in class Datum
      Returns:
      a Java String value
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getOracleYear

      public static int getOracleYear(Calendar cal)
    • getOracleYear

      public static int getOracleYear(int jYear)
    • dateValue

      public Date dateValue() throws SQLException
      Calls toDate to convert internal Oracle TIMESTAMP to a Java Date.
      Overrides:
      dateValue in class Datum
      Returns:
      a Java Date Object
      Throws:
      SQLException
    • timeValue

      public Time timeValue() throws SQLException
      Calls toTime to convert internal Oracle Date to a Java Time.
      Overrides:
      timeValue in class Datum
      Returns:
      a Java Time value
      Throws:
      SQLException
    • getJavaYear

      public static int getJavaYear(int cent, int decade)
    • of

      public static TIMESTAMP of(LocalDateTime ldt) throws SQLException
      Creates TIMESTAMP from the LocalDateTime.
      Parameters:
      ldt - LocalDateTime object
      Returns:
      TIMESTAMP object
      Throws:
      SQLException
    • toLocalDateTime

      public LocalDateTime toLocalDateTime() throws SQLException
      Converts TIMESTAMP to LocalDateTime.
      Returns:
      LocalDateTime object.
      Throws:
      SQLException
    • localDateTimeValue

      public LocalDateTime localDateTimeValue() throws SQLException
      Converts TIMESTAMP to LocalDateTime.
      Returns:
      LocalDateTime object.
      Throws:
      SQLException
    • of

      public static TIMESTAMP of(OffsetDateTime odt)
      Create a TIMESTAMP object given a Java OffsetDateTime
      Parameters:
      odt - OffsetDateTime object
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(byte[] timestamp) throws 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:
      SQLException
    • toLocalTime

      public static LocalTime toLocalTime(byte[] timestamp) throws 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:
      SQLException
    • toLocalDate

      public static LocalDate toLocalDate(byte[] timestamp) throws 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:
      SQLException
    • of

      public static TIMESTAMP of(ZonedDateTime zdt)
      Create a TIMESTAMP object given a Java ZonedDateTime
      Parameters:
      zdt - ZonedDateTime object
    • of

      public static TIMESTAMP of(OffsetTime ot)
      Create a TIMESTAMP object given a Java OffsetTime
      Parameters:
      ot - OffsetTime object
    • of

      public static TIMESTAMP of(LocalTime lt) throws SQLException
      Creates TIMESTAMP from the LocalTime.
      Parameters:
      lt - LocalTime object
      Returns:
      TIMESTAMP object
      Throws:
      SQLException
    • toLocalTime

      public LocalTime toLocalTime() throws SQLException
      Converts TIMESTAMP to LocalTime.
      Returns:
      LocalTime object.
      Throws:
      SQLException
    • localTimeValue

      public LocalTime localTimeValue() throws SQLException
      Converts TIMESTAMP to LocalTime.
      Returns:
      LocalTime object.
      Throws:
      SQLException
    • of

      public static TIMESTAMP of(LocalDate ld) throws SQLException
      Creates TIMESTAMP from the LocalDate.
      Parameters:
      ld - LocalDate object
      Returns:
      TIMESTAMP object
      Throws:
      SQLException
    • toLocalDate

      public LocalDate toLocalDate() throws SQLException
      Converts TIMESTAMP to LocalDate.
      Returns:
      LocalDate object.
      Throws:
      SQLException
    • localDateValue

      public LocalDate localDateValue() throws SQLException
      Converts TIMESTAMP to LocalDate.
      Returns:
      LocalTime object.
      Throws:
      SQLException
    • toBytes

      public static byte[] toBytes(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(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(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(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(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(LocalTime lt)
      Convert Java LocalTime to Oracle TIMESTAMP
      Parameters:
      lt - LocalTime object
      Returns:
      the byte array representing the java LocalTime.