public final class Timestamp extends Object implements Comparable<Timestamp>, Serializable
Timestamp
instances are immutable.
Modifier and Type | Field and Description |
---|---|
static Timestamp |
MAX_VALUE
The largest legal timestamp ("9999-12-31T23:59:59Z").
|
static Timestamp |
MIN_VALUE
The smallest legal timestamp ("0001-01-01T00:00:00Z").
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Timestamp other) |
boolean |
equals(Object o) |
static Timestamp |
fromProto(Timestamp proto)
Creates an instance of Timestamp from
com.google.protobuf.Timestamp . |
int |
getNanos()
Returns the fractional seconds component, in nanoseconds.
|
long |
getSeconds()
Returns the number of seconds since January 1, 1970, 00:00:00 UTC.
|
int |
hashCode() |
static Timestamp |
now()
Creates an instance with current time.
|
static Timestamp |
of(Date date)
Creates an instance representing the value of
Date . |
static Timestamp |
of(Timestamp timestamp)
Creates an instance representing the value of
timestamp . |
static Timestamp |
ofTimeMicroseconds(long microseconds)
Creates an instance representing the value of
microseconds . |
static Timestamp |
ofTimeSecondsAndNanos(long seconds,
int nanos)
Creates an instance representing the value of
seconds and nanos since January
1, 1970, 00:00:00 UTC. |
static Timestamp |
parseTimestamp(String timestamp)
Creates a Timestamp instance from the given string.
|
Date |
toDate()
Returns a new
java.util.Date corresponding to this timestamp . |
Timestamp |
toProto()
Returns a
com.google.protobuf.Timestamp initialized to the same point in time as this . |
Timestamp |
toSqlTimestamp()
Returns a JDBC timestamp initialized to the same point in time as
this . |
String |
toString() |
public static final Timestamp MIN_VALUE
public static final Timestamp MAX_VALUE
public static Timestamp ofTimeSecondsAndNanos(long seconds, int nanos)
seconds
and nanos
since January
1, 1970, 00:00:00 UTC.seconds
- seconds since January 1, 1970, 00:00:00 UTC. A negative value is the number of
seconds before January 1, 1970, 00:00:00 UTC.nanos
- the fractional seconds component, in the range 0..999999999.IllegalArgumentException
- if the timestamp is outside the representable rangepublic static Timestamp ofTimeMicroseconds(long microseconds)
microseconds
.IllegalArgumentException
- if the timestamp is outside the representable rangepublic static Timestamp of(Date date)
Date
.IllegalArgumentException
- if the timestamp is outside the representable rangepublic static Timestamp now()
public static Timestamp of(Timestamp timestamp)
timestamp
.IllegalArgumentException
- if the timestamp is outside the representable rangepublic long getSeconds()
public int getNanos()
public Timestamp toSqlTimestamp()
this
.public Date toDate()
java.util.Date
corresponding to this timestamp
. Any
sub-millisecond precision will be stripped.java.util.Date
representation of this timestamp
.public int compareTo(Timestamp other)
compareTo
in interface Comparable<Timestamp>
public static Timestamp fromProto(Timestamp proto)
com.google.protobuf.Timestamp
.public Timestamp toProto()
com.google.protobuf.Timestamp
initialized to the same point in time as this
.public static Timestamp parseTimestamp(String timestamp)
Copyright © 2019 Google LLC. All rights reserved.