java.sql

Class Timestamp

public class Timestamp extends Date

This class is a wrapper around java.util.Date to allow the JDBC driver to identify the value as a SQL Timestamp. Note that this class also adds an additional field for nano-seconds, and so is not completely identical to java.util.Date as the java.sql.Date and java.sql.Time classes are.
Constructor Summary
Timestamp(int year, int month, int day, int hour, int minute, int second, int nanos)
This method initializes a new instance of this class with the specified year, month, and day.
Timestamp(long date)
This method initializes a new instance of this class with the specified time value representing the number of milliseconds since Jan 1, 1970 at 12:00 midnight GMT.
Method Summary
booleanafter(Timestamp ts)
This methods tests whether this object is later than the specified object.
booleanbefore(Timestamp ts)
This methods tests whether this object is earlier than the specified object.
intcompareTo(Timestamp ts)
Compares this Timestamp to another one.
intcompareTo(Date obj)
Compares this Timestamp to another one.
booleanequals(Object obj)
This method these the specified Object for equality against this object.
booleanequals(Timestamp ts)
This method tests the specified timestamp for equality against this object.
intgetNanos()
This method returns the nanosecond value for this object.
longgetTime()
Return the value of this Timestamp as the number of milliseconds since Jan 1, 1970 at 12:00 midnight GMT.
voidsetNanos(int nanos)
This method sets the nanosecond value for this object.
StringtoString()
This method returns this date in JDBC format.
static TimestampvalueOf(String str)
This method returns a new instance of this class by parsing a date in JDBC format into a Java date.

Constructor Detail

Timestamp

public Timestamp(int year, int month, int day, int hour, int minute, int second, int nanos)

Deprecated:

This method initializes a new instance of this class with the specified year, month, and day.

Parameters: year The year for this Timestamp (year - 1900) month The month for this Timestamp (0-11) day The day for this Timestamp (1-31) hour The hour for this Timestamp (0-23) minute The minute for this Timestamp (0-59) second The second for this Timestamp (0-59) nanos The nanosecond value for this Timestamp (0 to 999,999,9999)

Timestamp

public Timestamp(long date)
This method initializes a new instance of this class with the specified time value representing the number of milliseconds since Jan 1, 1970 at 12:00 midnight GMT.

Parameters: date The time value to intialize this Time to.

Method Detail

after

public boolean after(Timestamp ts)
This methods tests whether this object is later than the specified object.

Parameters: ts The other Timestamp to test against.

Returns: true if this object is later than the other object, false otherwise.

before

public boolean before(Timestamp ts)
This methods tests whether this object is earlier than the specified object.

Parameters: ts The other Timestamp to test against.

Returns: true if this object is earlier than the other object, false otherwise.

compareTo

public int compareTo(Timestamp ts)
Compares this Timestamp to another one.

Parameters: ts The other Timestamp.

Returns: 0, if both Timestamp's represent exactly the same date, a negative value if this Timestamp is before the specified Timestamp and a positive value otherwise.

Since: 1.2

compareTo

public int compareTo(Date obj)
Compares this Timestamp to another one. This behaves like compareTo(Timestamp), but it may throw a ClassCastException, if the specified object is not of type Timestamp.

Parameters: obj The object to compare with.

Returns: 0, if both Timestamp's represent exactly the same date, a negative value if this Timestamp is before the specified Timestamp and a positive value otherwise.

Throws: ClassCastException if obj is not of type Timestamp.

Since: 1.2

See Also: compareTo

equals

public boolean equals(Object obj)
This method these the specified Object for equality against this object. This will be true if an only if the specified object is an instance of Timestamp and has the same time value fields.

Parameters: obj The object to test against for equality.

Returns: true if the specified object is equal to this object, false otherwise.

equals

public boolean equals(Timestamp ts)
This method tests the specified timestamp for equality against this object. This will be true if and only if the specified object is not null and contains all the same time value fields as this object.

Parameters: ts The Timestamp to test against for equality.

Returns: true if the specified object is equal to this object, false otherwise.

getNanos

public int getNanos()
This method returns the nanosecond value for this object.

Returns: The nanosecond value for this object.

getTime

public long getTime()
Return the value of this Timestamp as the number of milliseconds since Jan 1, 1970 at 12:00 midnight GMT.

setNanos

public void setNanos(int nanos)
This method sets the nanosecond value for this object.

Parameters: nanos The nanosecond value for this object.

toString

public String toString()
This method returns this date in JDBC format.

Returns: This date as a string.

valueOf

public static Timestamp valueOf(String str)
This method returns a new instance of this class by parsing a date in JDBC format into a Java date.

Parameters: str The string to parse.

Returns: The resulting java.sql.Timestamp value.