java.sql
Class Timestamp

java.lang.Object
  extended by java.util.Date
      extended by java.sql.Timestamp
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Date>

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.

See Also:
Serialized Form

Constructor Summary
Timestamp(int year, int month, int day, int hour, int minute, int second, int nanos)
          Deprecated.  
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
 boolean after(Timestamp ts)
          This methods tests whether this object is later than the specified object.
 boolean before(Timestamp ts)
          This methods tests whether this object is earlier than the specified object.
 int compareTo(Date obj)
          Compares this Timestamp to another one.
 int compareTo(Timestamp ts)
          Compares this Timestamp to another one.
 boolean equals(Object obj)
          This method these the specified Object for equality against this object.
 boolean equals(Timestamp ts)
          This method tests the specified timestamp for equality against this object.
 int getNanos()
          This method returns the nanosecond value for this object.
 long getTime()
          Return the value of this Timestamp as the number of milliseconds since Jan 1, 1970 at 12:00 midnight GMT.
 void setNanos(int nanos)
          This method sets the nanosecond value for this object.
 String toString()
          This method returns this date in JDBC format.
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.
 
Methods inherited from class java.util.Date
after, before, clone, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTimezoneOffset, getYear, hashCode, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setTime, setYear, toGMTString, toLocaleString, UTC
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

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

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.

getTime

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

Overrides:
getTime in class Date
Returns:
the time in milliseconds since the epoch.

toString

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

Overrides:
toString in class Date
Returns:
This date as a string.
See Also:
Date.parse(String), DateFormat

getNanos

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

Returns:
The nanosecond value for this object.

setNanos

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

Parameters:
nanos - The nanosecond value for this object.

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.

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.

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.

Overrides:
equals in class Date
Parameters:
obj - The object to test against for equality.
Returns:
true if the specified object is equal to this object, false otherwise.
See Also:
Object.hashCode()

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.

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.

Specified by:
compareTo in interface Comparable<Date>
Overrides:
compareTo in class Date
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(Timestamp)