GeezerVison is showing docs.oracle.com — Timestamp (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact2, compact3
java.sql
Class Timestamp
-
-
Constructor Summary
Constructors
| Constructor |
Description |
Timestamp(int year,
int month,
int date,
int hour,
int minute,
int second,
int nano) |
Deprecated.
instead use the constructor Timestamp(long millis)
|
Timestamp(long time) |
Constructs a Timestamp object
using a milliseconds time value.
|
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
boolean |
after(Timestamp ts) |
Indicates whether this Timestamp object is
later than the given Timestamp object.
|
boolean |
before(Timestamp ts) |
Indicates whether this Timestamp object is
earlier than the given Timestamp object.
|
int |
compareTo(Date o) |
Compares this Timestamp object to the given
Date object.
|
int |
compareTo(Timestamp ts) |
Compares this Timestamp object to the given
Timestamp object.
|
boolean |
equals(Object ts) |
Tests to see if this Timestamp object is
equal to the given object.
|
boolean |
equals(Timestamp ts) |
Tests to see if this Timestamp object is
equal to the given Timestamp object.
|
static Timestamp |
from(Instant instant) |
Obtains an instance of Timestamp from an Instant object.
|
int |
getNanos() |
Gets this Timestamp object's nanos value.
|
long |
getTime() |
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
represented by this Timestamp object.
|
int |
hashCode() |
Returns a hash code value for this object.
|
void |
setNanos(int n) |
Sets this Timestamp object's nanos field
to the given value.
|
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.
|
Instant |
toInstant() |
Converts this Timestamp object to an Instant.
|
LocalDateTime |
toLocalDateTime() |
Converts this Timestamp object to a LocalDateTime.
|
String |
toString() |
Formats a timestamp in JDBC timestamp escape format.
|
static Timestamp |
valueOf(LocalDateTime dateTime) |
Obtains an instance of Timestamp from a LocalDateTime
object, with the same year, month, day of month, hours, minutes,
seconds and nanos date-time value as the provided LocalDateTime.
|
static Timestamp |
valueOf(String s) |
Converts a String object in JDBC timestamp escape format to a
Timestamp value.
|
-
Methods inherited from class java.util.Date
after, before, clone, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTimezoneOffset, getYear, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setYear, toGMTString, toLocaleString, UTC
-
-
Constructor Detail
-
Timestamp
@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 - if the nano argument is out of bounds
-
Timestamp
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:
Calendar
-
Method Detail
-
setTime
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 in class Date
- Parameters:
time - the number of milliseconds.
- See Also:
getTime(),
Timestamp(long time),
Calendar
-
toString
public String toString()
Formats a timestamp in JDBC timestamp escape format.
yyyy-mm-dd hh:mm:ss.fffffffff,
where ffffffffff indicates nanoseconds.
- Overrides:
toString in class Date
- Returns:
- a
String object in
yyyy-mm-dd hh:mm:ss.fffffffff format
- See Also:
Date.toLocaleString(),
Date.toGMTString()
-
equals
public boolean equals(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 in class Date
- 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
- See Also:
Date.getTime()
-
hashCode
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 Date.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.
- Overrides:
hashCode in class Date
- Returns:
- a hash code value for this object.
- See Also:
Object.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|