Class TimestampValue

java.lang.Object
oracle.nosql.driver.values.FieldValue
oracle.nosql.driver.values.TimestampValue
All Implemented Interfaces:
Comparable<FieldValue>

public class TimestampValue extends FieldValue
A FieldValue instance representing a timestamp value. TimestampValue represents an instant in time in UTC. TimestampValue always stores its state in UTC. Instances can be created from long values which represent the number of milliseconds since the Epoch, 1970-01-01T00:00:00. They can also be created from string values in a valid ISO 8601 format. String formats without an explicit time zone are interpreted as UTC time.

TimestampValue is directly correlated to the database type of the same name and should be used during value construction for fields of that datatype.

  • Constructor Details

    • TimestampValue

      public TimestampValue(long millisecond)
      Creates a new instance from milliseconds since the Epoch.
      Parameters:
      millisecond - the number of milliseconds since the Epoch, "1970-01-01T00:00:00".
    • TimestampValue

      public TimestampValue(String value)
      Creates a new instance using an ISO 8601 formatted string. If timezone is not specified it is interpreted as UTC.
      Parameters:
      value - the string of a Timestamp in ISO 8601 format "uuuu-MM-dd['T'HH:mm:ss[.f..f]]".
    • TimestampValue

      public TimestampValue(String value, String pattern, boolean useUTC)
      Creates a TimestampValue instance from a String with specified pattern.
      Parameters:
      value - a timestamp string in the format of the specified pattern or the default pattern, "uuuu-MM-dd['T'HH:mm:ss[.f..f]]", which is used if pattern is null.
      pattern - the pattern for the timestampString. If null, then default pattern "uuuu-MM-dd['T'HH:mm:ss[.f..f]]" is used to parse the string. The symbols that can be used to specify a pattern are described in DateTimeFormatter.
      useUTC - if true the UTC time zone is used as default zone when parsing the string, otherwise the local time zone is used. If the timestampString has zone information, then that zone will be used.
      Throws:
      IllegalArgumentException - if the string cannot be parsed with the the given pattern correctly.
    • TimestampValue

      public TimestampValue(Timestamp value)
      Creates a new instance from a Java Timestamp
      Parameters:
      value - the Timestamp value
  • Method Details

    • getType

      public FieldValue.Type getType()
      Description copied from class: FieldValue
      Returns the type of the object
      Specified by:
      getType in class FieldValue
      Returns:
      the type
    • getValue

      public Timestamp getValue()
      Returns the Java Timestamp value of this object
      Returns:
      the Timestamp value
    • getLong

      public long getLong()
      Returns the long value of this object as the number of millisecond since the Epoch, 1970-01-01T00:00:00.
      Overrides:
      getLong in class FieldValue
      Returns:
      the long value
    • getNumber

      public BigDecimal getNumber()
      Returns a BigDecimal value for this object based on its long value.
      Overrides:
      getNumber in class FieldValue
      Returns:
      the BigDecimal value
    • getString

      public String getString()
      Returns the string value of this object, it is in the ISO 8601 format "uuuu-MM-dd'T'HH:mm:ss[.f..f]" and the time zone is UTC.
      Overrides:
      getString in class FieldValue
      Returns:
      the string value
    • compareTo

      public int compareTo(FieldValue other)
    • toJson

      public String toJson(JsonOptions options)
      Returns the JSON value of the instance. If JsonOptions.getTimestampAsLong() is true it is returned as a simple long value; otherwise it is returned as a quoted string using the ISO 8601 format.
      Overrides:
      toJson in class FieldValue
      Parameters:
      options - a JsonOptions instance to indicate non-default values, may be null.
      Returns:
      the string value.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object