Package oracle.nosql.driver.values
Class TimestampValue
- java.lang.Object
-
- oracle.nosql.driver.values.FieldValue
-
- oracle.nosql.driver.values.TimestampValue
-
- All Implemented Interfaces:
java.lang.Comparable<FieldValue>
public class TimestampValue extends FieldValue
AFieldValueinstance 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class oracle.nosql.driver.values.FieldValue
FieldValue.Type
-
-
Constructor Summary
Constructors Constructor Description TimestampValue(long millisecond)Creates a new instance from milliseconds since the Epoch.TimestampValue(java.lang.String value)Creates a new instance using an ISO 8601 formatted string.TimestampValue(java.lang.String value, java.lang.String pattern, boolean useUTC)Creates a TimestampValue instance from a String with specified pattern.TimestampValue(java.sql.Timestamp value)Creates a new instance from a JavaTimestamp
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(FieldValue other)booleanequals(java.lang.Object other)longgetLong()Returns the long value of this object as the number of millisecond since the Epoch, 1970-01-01T00:00:00.java.lang.StringgetString()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.FieldValue.TypegetType()Returns the type of the objectjava.sql.TimestampgetValue()Returns the JavaTimestampvalue of this objectinthashCode()java.lang.StringtoJson(JsonOptions options)Returns the JSON value of the instance.-
Methods inherited from class oracle.nosql.driver.values.FieldValue
asArray, asBinary, asBoolean, asDouble, asInteger, asJsonNull, asLong, asMap, asNull, asNumber, asString, asTimestamp, castAsDouble, createFromJson, createFromJson, createFromJson, getBinary, getBoolean, getDouble, getInt, getNumber, getSerializedSize, getTimestamp, isAtomic, isJsonNull, isNull, isNumeric, toJson, toString
-
-
-
-
Constructor Detail
-
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(java.lang.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(java.lang.String value, java.lang.String pattern, boolean useUTC)Creates a TimestampValue instance from a String with specified pattern.- Parameters:
value- a timestamp string in the format of the specifiedpatternor the default pattern, "uuuu-MM-dd['T'HH:mm:ss[.f..f]]", which is used ifpatternis 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 inDateTimeFormatter.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:
java.lang.IllegalArgumentException- if the string cannot be parsed with the the given pattern correctly.
-
TimestampValue
public TimestampValue(java.sql.Timestamp value)
Creates a new instance from a JavaTimestamp- Parameters:
value- the Timestamp value
-
-
Method Detail
-
getType
public FieldValue.Type getType()
Description copied from class:FieldValueReturns the type of the object- Specified by:
getTypein classFieldValue- Returns:
- the type
-
getValue
public java.sql.Timestamp getValue()
Returns the JavaTimestampvalue 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:
getLongin classFieldValue- Returns:
- the long value
-
getString
public java.lang.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:
getStringin classFieldValue- Returns:
- the string value
-
compareTo
public int compareTo(FieldValue other)
-
toJson
public java.lang.String toJson(JsonOptions options)
Returns the JSON value of the instance. IfJsonOptions.getTimestampAsLong()is true it is returned as a simple long value; otherwise it is returned as a quoted string using the ISO 8601 format.- Specified by:
toJsonin classFieldValue- Parameters:
options- a JsonOptions instance to indicate non-default values, may be null.- Returns:
- the string value.
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-