加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090309181029/http://developer.android.com:80/reference/java/sql/Timestamp.html
public class

Timestamp

extends Date
java.lang.Object
   ↳ java.util.Date
     ↳ java.sql.Timestamp

Class Overview

A Java representation of the SQL TIMESTAMP type. It provides the capability to represent the SQL TIMESTAMP nanosecond value, in addition to the regular date/time value which has millisecond resolution.

The Timestamp class consists of a regular Date/Time value, where only the integral seconds value is stored, plus a nanoseconds value where the fractional seconds are stored.

The addition of the nanosecond value field to the Timestamp object makes it significantly different from the java.util.Date object which it extends. Users should be cautious in their use of Timestamp objects and should not assume that they are interchangeable with java.util.Date objects when used outside the confines of the java.sql package.

Summary

Public Constructors
Timestamp(int theYear, int theMonth, int theDate, int theHour, int theMinute, int theSecond, int theNano)
This constructor is deprecated. Please use the constructor Timestamp(long) Returns a Timestamp corresponding to the time specified by the supplied values for Year, Month, Date, Hour, Minutes, Seconds and Nanoseconds
Timestamp(long theTime)
Returns a Timestamp object corresponding to the time represented by a supplied time value.
Public Methods
boolean after(Timestamp theTimestamp)
Returns true if this timestamp object is later than the supplied timestamp, otherwise returns false.
boolean before(Timestamp theTimestamp)
Returns true if this timestamp object is earlier than the supplied timestamp, otherwise returns false.
int compareTo(Date theObject)
Compares this Timestamp object with a supplied Timestamp object
int compareTo(Timestamp theTimestamp)
Compares this Timestamp object with a supplied Timestamp object
boolean equals(Object theObject)
Tests to see if this timestamp is equal to a supplied object.
boolean equals(Timestamp theTimestamp)
Tests to see if this timestamp is equal to a supplied timestamp.
int getNanos()
Gets this Timestamp's nanosecond value
long getTime()
Returns the time represented by this Timestamp object, as a long value containing the number of milliseconds since the Epoch (January 1 1970, 00:00:00.000 GMT)
void setNanos(int n)
Sets the nanosecond value for this timestamp
void setTime(long theTime)
Sets the time represented by this Timestamp object to the supplied time, defined as the number of milliseconds since the Epoch (January 1 1970, 00:00:00.000 GMT)
String toString()
Returns the timestamp formatted as a String in the JDBC Timestamp Escape format, which is of the form "yyyy-mm-dd hh:mm:ss.nnnnnnnnn"
static Timestamp valueOf(String s)
Creates a Timestamp object with a time value equal to the time specified by a supplied String holding the time in JDBC timestamp escape format, which is of the form "yyyy-mm-dd hh:mm:ss.nnnnnnnnn"
[Expand]
Inherited Methods
From class java.util.Date
From class java.lang.Object
From interface java.lang.Comparable

Public Constructors

public Timestamp (int theYear, int theMonth, int theDate, int theHour, int theMinute, int theSecond, int theNano)

This constructor is deprecated.Please use the constructor Timestamp(long) Returns a Timestamp corresponding to the time specified by the supplied values for Year, Month, Date, Hour, Minutes, Seconds and Nanoseconds

Parameters
theYear specified as the year minus 1900
theMonth specified as an integer in the range 0 - 11
theDate specified as an integer in the range 1 - 31
theHour specified as an integer in the range 0 - 23
theMinute specified as an integer in the range 0 - 59
theSecond specified as an integer in the range 0 - 59
theNano which defines the nanosecond value of the timestamp specified as an integer in the range 0 - 999,999,999
Throws
IllegalArgumentException if any of the parameters is out of range

public Timestamp (long theTime)

Returns a Timestamp object corresponding to the time represented by a supplied time value.

Parameters
theTime a time value in the format of milliseconds since the Epoch (January 1 1970 00:00:00.000 GMT)

Public Methods

public boolean after (Timestamp theTimestamp)

Returns true if this timestamp object is later than the supplied timestamp, otherwise returns false.

Parameters
theTimestamp the timestamp to compare with this timestamp object
Returns
  • true if this timestamp object is later than the supplied timestamp, false otherwise

public boolean before (Timestamp theTimestamp)

Returns true if this timestamp object is earlier than the supplied timestamp, otherwise returns false.

Parameters
theTimestamp the timestamp to compare with this timestamp object
Returns
  • true if this timestamp object is earlier than the supplied timestamp, false otherwise

public int compareTo (Date theObject)

Compares this Timestamp object with a supplied Timestamp object

Parameters
theObject the timestamp to compare with this timestamp object, passed in as an Object
Returns
  • 0 if the two Timestamp objects are equal in time, a value <0 if this Timestamp object is before the supplied Timestamp and a value >0 if this Timestamp object is after the supplied Timestamp
Throws
ClassCastException if the supplied object is not a Timestamp object

public int compareTo (Timestamp theTimestamp)

Compares this Timestamp object with a supplied Timestamp object

Parameters
theTimestamp the timestamp to compare with this timestamp object, passed in as a Timestamp
Returns
  • 0 if the two Timestamp objects are equal in time, a value <0 if this Timestamp object is before the supplied Timestamp and a value >0 if this Timestamp object is after the supplied Timestamp

public boolean equals (Object theObject)

Tests to see if this timestamp is equal to a supplied object.

Parameters
theObject the object to compare with this object
Returns
  • true if this Timestamp object is equal to the supplied Timestamp object false if the object is not a Timestamp object or if the object is a Timestamp but represents a different instant in time

public boolean equals (Timestamp theTimestamp)

Tests to see if this timestamp is equal to a supplied timestamp.

Parameters
theTimestamp the timestamp to compare with this timestamp object, passed in as an Object
Returns
  • true if this Timestamp object is equal to the supplied Timestamp object

public int getNanos ()

Gets this Timestamp's nanosecond value

Returns
  • The timestamp's nanosecond value, an integer between 0 and 999,999,999

public long getTime ()

Returns the time represented by this Timestamp object, as a long value containing the number of milliseconds since the Epoch (January 1 1970, 00:00:00.000 GMT)

Returns
  • the number of milliseconds since Jan. 1, 1970 GMT.

public void setNanos (int n)

Sets the nanosecond value for this timestamp

Parameters
n number of nanoseconds
Throws
IllegalArgumentException if number of nanoseconds smaller than 0 or greater than 999999999

public void setTime (long theTime)

Sets the time represented by this Timestamp object to the supplied time, defined as the number of milliseconds since the Epoch (January 1 1970, 00:00:00.000 GMT)

Parameters
theTime the number of milliseconds since Jan. 1, 1970 GMT.

public String toString ()

Returns the timestamp formatted as a String in the JDBC Timestamp Escape format, which is of the form "yyyy-mm-dd hh:mm:ss.nnnnnnnnn"

Returns
  • A string representing the instant defined by the Timestamp, in JDBC Timestamp escape format

public static Timestamp valueOf (String s)

Creates a Timestamp object with a time value equal to the time specified by a supplied String holding the time in JDBC timestamp escape format, which is of the form "yyyy-mm-dd hh:mm:ss.nnnnnnnnn"

Parameters
s the String containing a time in JDBC timestamp escape format
Returns
  • A timestamp object with time value as defined by the supplied String
Throws
IllegalArgumentException if the provided String is null