# Timestamp

public class **Timestamp** extends [Date](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html)  
<br />

A thin wrapper around `java.util.Date` that allows
the JDBC API to identify this as an SQL `TIMESTAMP` value.
It adds the ability
to hold the SQL `TIMESTAMP` fractional seconds value, by allowing
the specification of fractional seconds to a precision of nanoseconds.
A Timestamp also provides formatting and
parsing operations to support the JDBC escape syntax for timestamp values.

The precision of a Timestamp object is calculated to be either:

- `19 `, which is the number of characters in yyyy-mm-dd hh:mm:ss
- ` 20 + s `, which is the number of characters in the yyyy-mm-dd hh:mm:ss.\[fff...\] and `s` represents the scale of the given Timestamp, its fractional seconds precision.

**Note:** This type is a composite of a `java.util.Date` and a
separate nanoseconds value. Only integral seconds are stored in the
`java.util.Date` component. The fractional seconds - the nanos - are
separate. The `Timestamp.equals(Object)` method never returns
`true` when passed an object
that isn't an instance of `java.sql.Timestamp`,
because the nanos component of a date is unknown.
As a result, the `Timestamp.equals(Object)`
method is not symmetric with respect to the
`java.util.Date.equals(Object)`
method. Also, the `hashCode` method uses the underlying
`java.util.Date`
implementation and therefore does not include nanos in its computation.


Due to the differences between the `Timestamp` class
and the `java.util.Date`
class mentioned above, it is recommended that code not view
`Timestamp` values generically as an instance of
`java.util.Date`. The
inheritance relationship between `Timestamp`
and `java.util.Date` really
denotes implementation inheritance, and not type inheritance.

### Public Constructor Summary

|---|---|
|   | [Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#Timestamp(int,%20int,%20int,%20int,%20int,%20int,%20int))(int year, int month, int date, int hour, int minute, int second, int nano) *This constructor is deprecated. instead use the constructor `Timestamp(long millis)`* |
|   | [Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#Timestamp(long))(long time) Constructs a `Timestamp` object using a milliseconds time value. |

### Public Method Summary

|---|---|
| boolean | [after](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#after(java.sql.Timestamp))([Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html) ts) Indicates whether this `Timestamp` object is later than the given `Timestamp` object. |
| boolean | [before](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#before(java.sql.Timestamp))([Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html) ts) Indicates whether this `Timestamp` object is earlier than the given `Timestamp` object. |
| int | [compareTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#compareTo(java.util.Date))([Date](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html) o) Compares this `Timestamp` object to the given `Date` object. |
| int | [compareTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#compareTo(java.sql.Timestamp))([Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html) ts) Compares this `Timestamp` object to the given `Timestamp` object. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#equals(java.sql.Timestamp))([Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html) ts) Tests to see if this `Timestamp` object is equal to the given `Timestamp` object. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) ts) Tests to see if this `Timestamp` object is equal to the given object. |
| int | [getNanos](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#getNanos())() Gets this `Timestamp` object's `nanos` value. |
| long | [getTime](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#getTime())() Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this `Timestamp` object. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#hashCode())() Returns a hash code value for this object. The `hashCode` method uses the underlying `java.util.Date` implementation and therefore does not include nanos in its computation. |
| void | [setNanos](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#setNanos(int))(int n) Sets this `Timestamp` object's `nanos` field to the given value. |
| void | [setTime](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#setTime(long))(long time) Sets this `Timestamp` object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#toString())() Formats a timestamp in JDBC timestamp escape format. |
| static [Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html) | [valueOf](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#valueOf(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) s) Converts a `String` object in JDBC timestamp escape format to a `Timestamp` value. |

### Inherited Method Summary

From class [java.util.Date](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html)

|---|---|
| static long | [UTC](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#UTC(int,%20int,%20int,%20int,%20int,%20int))(int year, int month, int date, int hrs, int min, int sec) *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.set(year + 1900, month, date, hrs, min, sec)` or `GregorianCalendar(year + 1900, month, date, hrs, min, sec)`, using a UTC `TimeZone`, followed by `Calendar.getTime().getTime()`.* |
| boolean | [after](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#after(java.util.Date))([Date](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html) when) Tests if this date is after the specified date. |
| boolean | [before](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#before(java.util.Date))([Date](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html) when) Tests if this date is before the specified date. |
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#clone())() Return a copy of this object. |
| int | [compareTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#compareTo(java.util.Date))([Date](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html) anotherDate) Compares two Dates for ordering. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares two dates for equality. |
| int | [getDate](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#getDate())() *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.get(Calendar.DAY_OF_MONTH)`.* |
| int | [getDay](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#getDay())() *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.get(Calendar.DAY_OF_WEEK)`.* |
| int | [getHours](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#getHours())() *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.get(Calendar.HOUR_OF_DAY)`.* |
| int | [getMinutes](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#getMinutes())() *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.get(Calendar.MINUTE)`.* |
| int | [getMonth](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#getMonth())() *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.get(Calendar.MONTH)`.* |
| int | [getSeconds](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#getSeconds())() *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.get(Calendar.SECOND)`.* |
| long | [getTime](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#getTime())() Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object. |
| int | [getTimezoneOffset](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#getTimezoneOffset())() *This method is deprecated. As of JDK version 1.1, replaced by `-(Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) / (60 * 1000)`.* |
| int | [getYear](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#getYear())() *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.get(Calendar.YEAR) - 1900`.* |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#hashCode())() Returns a hash code value for this object. |
| static long | [parse](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#parse(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) s) *This method is deprecated. As of JDK version 1.1, replaced by `DateFormat.parse(String s)`.* |
| void | [setDate](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#setDate(int))(int date) *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.set(Calendar.DAY_OF_MONTH, int date)`.* |
| void | [setHours](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#setHours(int))(int hours) *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.set(Calendar.HOUR_OF_DAY, int hours)`.* |
| void | [setMinutes](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#setMinutes(int))(int minutes) *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.set(Calendar.MINUTE, int minutes)`.* |
| void | [setMonth](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#setMonth(int))(int month) *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.set(Calendar.MONTH, int month)`.* |
| void | [setSeconds](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#setSeconds(int))(int seconds) *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.set(Calendar.SECOND, int seconds)`.* |
| void | [setTime](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#setTime(long))(long time) Sets this `Date` object to represent a point in time that is `time` milliseconds after January 1, 1970 00:00:00 GMT. |
| void | [setYear](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#setYear(int))(int year) *This method is deprecated. As of JDK version 1.1, replaced by `Calendar.set(Calendar.YEAR, year + 1900)`.* |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toGMTString](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#toGMTString())() *This method is deprecated. As of JDK version 1.1, replaced by `DateFormat.format(Date date)`, using a GMT `TimeZone`.* |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toLocaleString](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#toLocaleString())() *This method is deprecated. As of JDK version 1.1, replaced by `DateFormat.format(Date date)`.* |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#toString())() Converts this `Date` object to a `String` of the form: > ``` >  dow mon dd hh:mm:ss zzz yyyy > ``` where: - dow is the day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat). |

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.lang.Comparable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Comparable.html)

|---|---|
| abstract int | [compareTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Comparable.html#compareTo(T))([Date](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html) o) Compares this object with the specified object for order. |

## Public Constructors

#### public
**Timestamp**
(int year, int month, int date, int hour, int minute, int second, int nano)


**This constructor is deprecated.**   
instead use the constructor `Timestamp(long millis)`
Constructs a `Timestamp` object initialized
with the given values.

##### Parameters

| year | the year minus 1900 |
| month | 0 to 11 |
| date | 1 to 31 |
| hour | 0 to 23 |
| minute | 0 to 59 |
| second | 0 to 59 |
| nano | 0 to 999,999,999 |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the nano argument is out of bounds |
|---|---|

#### public
**Timestamp**
(long time)

Constructs a `Timestamp` object
using a milliseconds time value. The
integral seconds are stored in the underlying date value; the
fractional seconds are stored in the `nanos` field of
the `Timestamp` object.

##### Parameters

| time | milliseconds since January 1, 1970, 00:00:00 GMT. A negative number is the number of milliseconds before January 1, 1970, 00:00:00 GMT. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Calendar.html`

## Public Methods

#### public boolean
**after**
([Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html) ts)

Indicates whether this `Timestamp` object is
later than the given `Timestamp` object.

##### Parameters

| ts | the `Timestamp` value to compare with |
|---|---|

##### Returns

- `true` if this `Timestamp` object is later; `false` otherwise

#### public boolean
**before**
([Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html) ts)

Indicates whether this `Timestamp` object is
earlier than the given `Timestamp` object.

##### Parameters

| ts | the `Timestamp` value to compare with |
|---|---|

##### Returns

- `true` if this `Timestamp` object is earlier; `false` otherwise

#### public int
**compareTo**
([Date](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html) o)

Compares this `Timestamp` object to the given
`Date` object.

##### Parameters

| o | the `Date` to be compared to this `Timestamp` object |
|---|---|

##### Returns

- the value `0` if this `Timestamp` object and the given object are equal; a value less than `0` if this `Timestamp` object is before the given argument; and a value greater than `0` if this `Timestamp` object is after the given argument.

#### public int
**compareTo**
([Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html) ts)

Compares this `Timestamp` object to the given
`Timestamp` object.

##### Parameters

| ts | the `Timestamp` object to be compared to this `Timestamp` object |
|---|---|

##### Returns

- the value `0` if the two `Timestamp` objects are equal; a value less than `0` if this `Timestamp` object is before the given argument; and a value greater than `0` if this `Timestamp` object is after the given argument.

#### public boolean
**equals**
([Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html) ts)

Tests to see if this `Timestamp` object is
equal to the given `Timestamp` object.

##### Parameters

| ts | the `Timestamp` value to compare with |
|---|---|

##### Returns

- `true` if the given `Timestamp` object is equal to this `Timestamp` object; `false` otherwise

#### public boolean
**equals**
([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) ts)

Tests to see if this `Timestamp` object is
equal to the given object.

This version of the method `equals` has been added
to fix the incorrect
signature of `Timestamp.equals(Timestamp)` and to preserve backward
compatibility with existing class files.

Note: This method is not symmetric with respect to the
`equals(Object)` method in the base class.

##### Parameters

| ts | the `Object` value to compare with |
|---|---|

##### Returns

- `true` if the given `Object` is an instance of a `Timestamp` that is equal to this `Timestamp` object; `false` otherwise

#### public int
**getNanos**
()

Gets this `Timestamp` object's `nanos` value.

##### Returns

- this `Timestamp` object's fractional seconds component

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#setNanos(int)`

#### public long
**getTime**
()

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
represented by this `Timestamp` object.

##### Returns

- the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#setTime(long)`

#### public int
**hashCode**
()

Returns a hash code value for this object. The result is the
exclusive OR of the two halves of the primitive long
value returned by the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html#getTime()`
method. That is, the hash code is the value of the expression:
>
>     (int)(this.getTime()^(this.getTime() >>> 32))
>      
The `hashCode` method uses the underlying `java.util.Date` implementation and therefore does not include nanos in its computation.

<br />

##### Returns

- a hash code value for this object.

#### public void
**setNanos**
(int n)

Sets this `Timestamp` object's `nanos` field
to the given value.

##### Parameters

| n | the new fractional seconds component |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the given argument is greater than 999999999 or less than 0 |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#getNanos()`

#### public void
**setTime**
(long time)

Sets this `Timestamp` object to represent a point in time that is
time milliseconds after January 1, 1970 00:00:00 GMT.

##### Parameters

| time | the number of milliseconds. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#getTime()`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html#Timestamp(long)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Calendar.html`

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**toString**
()

Formats a timestamp in JDBC timestamp escape format.
`yyyy-mm-dd hh:mm:ss.fffffffff`,
where `ffffffffff` indicates nanoseconds.

<br />

##### Returns

- a `String` object in `yyyy-mm-dd hh:mm:ss.fffffffff` format

#### public static [Timestamp](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Timestamp.html)
**valueOf**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) s)

Converts a `String` object in JDBC timestamp escape format to a
`Timestamp` value.

##### Parameters

| s | timestamp in format `yyyy-[m]m-[d]d hh:mm:ss[.f...]`. The fractional seconds may be omitted. The leading zero for `mm` and `dd` may also be omitted. |
|---|---|

##### Returns

- corresponding `Timestamp` value

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the given argument does not have the format `yyyy-[m]m-[d]d hh:mm:ss[.f...]` |
|---|---|