java.sql
Class Timestamp

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

public class Timestamp
extends Date sample code for java.util.Date definition code for java.util.Date

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 nanos value and provides formatting and parsing operations to support the JDBC escape syntax for timestamp values.

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 a value of type java.util.Date 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.

See Also:
Serialized Form

Constructor Summary
Timestamp sample code for java.sql.Timestamp.Timestamp(int, int, int, int, int, int, int) definition code for java.sql.Timestamp.Timestamp(int, int, int, int, int, int, int) (int year, int month, int date, int hour, int minute, int second, int nano)
          Deprecated. instead use the constructor Timestamp(long millis)
Timestamp sample code for java.sql.Timestamp.Timestamp(long) definition code for java.sql.Timestamp.Timestamp(long) (long time)
          Constructs a Timestamp object using a milliseconds time value.
 
Method Summary
 boolean after sample code for java.sql.Timestamp.after(java.sql.Timestamp) definition code for java.sql.Timestamp.after(java.sql.Timestamp) (Timestamp sample code for java.sql.Timestamp definition code for java.sql.Timestamp  ts)
          Indicates whether this Timestamp object is later than the given Timestamp object.
 boolean before sample code for java.sql.Timestamp.before(java.sql.Timestamp) definition code for java.sql.Timestamp.before(java.sql.Timestamp) (Timestamp sample code for java.sql.Timestamp definition code for java.sql.Timestamp  ts)
          Indicates whether this Timestamp object is earlier than the given Timestamp object.
 int compareTo sample code for java.sql.Timestamp.compareTo(java.util.Date) definition code for java.sql.Timestamp.compareTo(java.util.Date) (Date sample code for java.util.Date definition code for java.util.Date  o)
          Compares this Timestamp object to the given Date, which must be a Timestamp object.
 int compareTo sample code for java.sql.Timestamp.compareTo(java.sql.Timestamp) definition code for java.sql.Timestamp.compareTo(java.sql.Timestamp) (Timestamp sample code for java.sql.Timestamp definition code for java.sql.Timestamp  ts)
          Compares this Timestamp object to the given Timestamp object.
 boolean equals sample code for java.sql.Timestamp.equals(java.lang.Object) definition code for java.sql.Timestamp.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  ts)
          Tests to see if this Timestamp object is equal to the given object.
 boolean equals sample code for java.sql.Timestamp.equals(java.sql.Timestamp) definition code for java.sql.Timestamp.equals(java.sql.Timestamp) (Timestamp sample code for java.sql.Timestamp definition code for java.sql.Timestamp  ts)
          Tests to see if this Timestamp object is equal to the given Timestamp object.
 int getNanos sample code for java.sql.Timestamp.getNanos() definition code for java.sql.Timestamp.getNanos() ()
          Gets this Timestamp object's nanos value.
 long getTime sample code for java.sql.Timestamp.getTime() definition code for java.sql.Timestamp.getTime() ()
          Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Timestamp object.
 void setNanos sample code for java.sql.Timestamp.setNanos(int) definition code for java.sql.Timestamp.setNanos(int) (int n)
          Sets this Timestamp object's nanos field to the given value.
 void setTime sample code for java.sql.Timestamp.setTime(long) definition code for java.sql.Timestamp.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 sample code for java.lang.String definition code for java.lang.String toString sample code for java.sql.Timestamp.toString() definition code for java.sql.Timestamp.toString() ()
          Formats a timestamp in JDBC timestamp escape format.
static Timestamp sample code for java.sql.Timestamp definition code for java.sql.Timestamp valueOf sample code for java.sql.Timestamp.valueOf(java.lang.String) definition code for java.sql.Timestamp.valueOf(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  s)
          Converts a String object in JDBC timestamp escape format to a Timestamp value.
 
Methods inherited from class java.util.Date sample code for java.util.Date definition code for java.util.Date
after sample code for java.util.Date.after(java.util.Date) definition code for java.util.Date.after(java.util.Date) , before sample code for java.util.Date.before(java.util.Date) definition code for java.util.Date.before(java.util.Date) , clone sample code for java.util.Date.clone() definition code for java.util.Date.clone() , getDate sample code for java.util.Date.getDate() definition code for java.util.Date.getDate() , getDay sample code for java.util.Date.getDay() definition code for java.util.Date.getDay() , getHours sample code for java.util.Date.getHours() definition code for java.util.Date.getHours() , getMinutes sample code for java.util.Date.getMinutes() definition code for java.util.Date.getMinutes() , getMonth sample code for java.util.Date.getMonth() definition code for java.util.Date.getMonth() , getSeconds sample code for java.util.Date.getSeconds() definition code for java.util.Date.getSeconds() , getTimezoneOffset sample code for java.util.Date.getTimezoneOffset() definition code for java.util.Date.getTimezoneOffset() , getYear sample code for java.util.Date.getYear() definition code for java.util.Date.getYear() , hashCode sample code for java.util.Date.hashCode() definition code for java.util.Date.hashCode() , parse sample code for java.util.Date.parse(java.lang.String) definition code for java.util.Date.parse(java.lang.String) , setDate sample code for java.util.Date.setDate(int) definition code for java.util.Date.setDate(int) , setHours sample code for java.util.Date.setHours(int) definition code for java.util.Date.setHours(int) , setMinutes sample code for java.util.Date.setMinutes(int) definition code for java.util.Date.setMinutes(int) , setMonth sample code for java.util.Date.setMonth(int) definition code for java.util.Date.setMonth(int) , setSeconds sample code for java.util.Date.setSeconds(int) definition code for java.util.Date.setSeconds(int) , setYear sample code for java.util.Date.setYear(int) definition code for java.util.Date.setYear(int) , toGMTString sample code for java.util.Date.toGMTString() definition code for java.util.Date.toGMTString() , toLocaleString sample code for java.util.Date.toLocaleString() definition code for java.util.Date.toLocaleString() , UTC sample code for java.util.Date.UTC(int, int, int, int, int, int) definition code for java.util.Date.UTC(int, int, int, int, int, int)
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

Timestamp sample code for java.sql.Timestamp(int, int, int, int, int, int, int) definition code for java.sql.Timestamp(int, int, int, int, int, int, int)

@Deprecated
public Timestamp(int year,
                            int month,
                            int date,
                            int hour,
                            int minute,
                            int second,
                            int nano)
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 sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the nano argument is out of bounds

Timestamp sample code for java.sql.Timestamp(long) definition code for java.sql.Timestamp(long)

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:
for more information sample code for java.util.Calendar definition code for java.util.Calendar
Method Detail

setTime sample code for java.sql.Timestamp.setTime(long) definition code for java.sql.Timestamp.setTime(long)

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.

Overrides:
setTime sample code for java.util.Date.setTime(long) definition code for java.util.Date.setTime(long) in class Date sample code for java.util.Date definition code for java.util.Date
Parameters:
time - the number of milliseconds.
See Also:
getTime() sample code for java.sql.Timestamp.getTime() definition code for java.sql.Timestamp.getTime() , Timestamp(long time) sample code for java.sql.Timestamp.Timestamp(long) definition code for java.sql.Timestamp.Timestamp(long) , for more information sample code for java.util.Calendar definition code for java.util.Calendar

getTime sample code for java.sql.Timestamp.getTime() definition code for java.sql.Timestamp.getTime()

public long getTime()
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Timestamp object.

Overrides:
getTime sample code for java.util.Date.getTime() definition code for java.util.Date.getTime() in class Date sample code for java.util.Date definition code for java.util.Date
Returns:
the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.
See Also:
setTime(long) sample code for java.sql.Timestamp.setTime(long) definition code for java.sql.Timestamp.setTime(long)

valueOf sample code for java.sql.Timestamp.valueOf(java.lang.String) definition code for java.sql.Timestamp.valueOf(java.lang.String)

public static Timestamp sample code for java.sql.Timestamp definition code for java.sql.Timestamp  valueOf(String sample code for java.lang.String definition code for java.lang.String  s)
Converts a String object in JDBC timestamp escape format to a Timestamp value.

Parameters:
s - timestamp in format yyyy-mm-dd hh:mm:ss.fffffffff
Returns:
corresponding Timestamp value
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the given argument does not have the format yyyy-mm-dd hh:mm:ss.fffffffff

toString sample code for java.sql.Timestamp.toString() definition code for java.sql.Timestamp.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Formats a timestamp in JDBC timestamp escape format. yyyy-mm-dd hh:mm:ss.fffffffff, where ffffffffff indicates nanoseconds.

NOTE: To specify a timestamp for the class java.text.SimpleDateFormat, use "yyyy.MM.dd" rather than "yyyy-mm-dd". In the context of java.text.SimpleDateFormat, "mm" indicates minutes rather than the month. Note that java.text.SimpleDateFormat does not allow for the nanoseconds component of a Timestamp object. For Example:


 Format Pattern                         Result
 --------------                         ------
 "yyyy.MM.dd G 'at' hh:mm:ss z" -->     2002.07.10 AD at 15:08:56 PDT

 

Overrides:
toString sample code for java.util.Date.toString() definition code for java.util.Date.toString() in class Date sample code for java.util.Date definition code for java.util.Date
Returns:
a String object in yyyy-mm-dd hh:mm:ss.fffffffff format
See Also:
Date.toLocaleString() sample code for java.util.Date.toLocaleString() definition code for java.util.Date.toLocaleString() , Date.toGMTString() sample code for java.util.Date.toGMTString() definition code for java.util.Date.toGMTString()

getNanos sample code for java.sql.Timestamp.getNanos() definition code for java.sql.Timestamp.getNanos()

public int getNanos()
Gets this Timestamp object's nanos value.

Returns:
this Timestamp object's fractional seconds component
See Also:
setNanos(int) sample code for java.sql.Timestamp.setNanos(int) definition code for java.sql.Timestamp.setNanos(int)

setNanos sample code for java.sql.Timestamp.setNanos(int) definition code for java.sql.Timestamp.setNanos(int)

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 sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the given argument is greater than 999999999 or less than 0
See Also:
getNanos() sample code for java.sql.Timestamp.getNanos() definition code for java.sql.Timestamp.getNanos()

equals sample code for java.sql.Timestamp.equals(java.sql.Timestamp) definition code for java.sql.Timestamp.equals(java.sql.Timestamp)

public boolean equals(Timestamp sample code for java.sql.Timestamp definition code for java.sql.Timestamp  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

equals sample code for java.sql.Timestamp.equals(java.lang.Object) definition code for java.sql.Timestamp.equals(java.lang.Object)

public boolean equals(Object sample code for java.lang.Object definition code for java.lang.Object  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.

Overrides:
equals sample code for java.util.Date.equals(java.lang.Object) definition code for java.util.Date.equals(java.lang.Object) in class Date sample code for java.util.Date definition code for java.util.Date
Parameters:
ts - the Object value to compare with
Returns:
true if the given Object instance is equal to this Timestamp object; false otherwise
See Also:
Date.getTime() sample code for java.util.Date.getTime() definition code for java.util.Date.getTime()

before sample code for java.sql.Timestamp.before(java.sql.Timestamp) definition code for java.sql.Timestamp.before(java.sql.Timestamp)

public boolean before(Timestamp sample code for java.sql.Timestamp definition code for java.sql.Timestamp  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

after sample code for java.sql.Timestamp.after(java.sql.Timestamp) definition code for java.sql.Timestamp.after(java.sql.Timestamp)

public boolean after(Timestamp sample code for java.sql.Timestamp definition code for java.sql.Timestamp  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

compareTo sample code for java.sql.Timestamp.compareTo(java.sql.Timestamp) definition code for java.sql.Timestamp.compareTo(java.sql.Timestamp)

public int compareTo(Timestamp sample code for java.sql.Timestamp definition code for java.sql.Timestamp  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.
Since:
1.2

compareTo sample code for java.sql.Timestamp.compareTo(java.util.Date) definition code for java.sql.Timestamp.compareTo(java.util.Date)

public int compareTo(Date sample code for java.util.Date definition code for java.util.Date  o)
Compares this Timestamp object to the given Date, which must be a Timestamp object. If the argument is not a Timestamp object, this method throws a ClassCastException object. (Timestamp objects are comparable only to other Timestamp objects.)

Specified by:
compareTo sample code for java.lang.Comparable.compareTo(T) definition code for java.lang.Comparable.compareTo(T) in interface Comparable sample code for java.lang.Comparable definition code for java.lang.Comparable <Date sample code for java.util.Date definition code for java.util.Date >
Overrides:
compareTo sample code for java.util.Date.compareTo(java.util.Date) definition code for java.util.Date.compareTo(java.util.Date) in class Date sample code for java.util.Date definition code for java.util.Date
Parameters:
o - the Date to be compared, which must be a 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.
Throws:
ClassCastException sample code for java.lang.ClassCastException definition code for java.lang.ClassCastException - if the argument is not a Timestamp object
Since:
1.5