@Immutable public abstract class Timestamp extends Object implements Comparable<Timestamp>
Use Tracing.getClock().now()
to get the current timestamp since epoch
(1970-01-01T00:00:00Z).
Modifier and Type | Method and Description |
---|---|
Timestamp |
addDuration(Duration duration)
Returns a
Timestamp calculated as this Timestamp plus some Duration . |
Timestamp |
addNanos(long nanosToAdd)
Returns a
Timestamp calculated as this Timestamp plus some number of
nanoseconds. |
int |
compareTo(Timestamp otherTimestamp)
Compares this
Timestamp to the specified Timestamp . |
static Timestamp |
create(long seconds,
int nanos)
Creates a new timestamp from given seconds and nanoseconds.
|
static Timestamp |
fromMillis(long epochMilli)
Creates a new timestamp from the given milliseconds.
|
abstract int |
getNanos()
Returns the number of nanoseconds after the number of seconds since the Unix Epoch represented
by this timestamp.
|
abstract long |
getSeconds()
Returns the number of seconds since the Unix Epoch represented by this timestamp.
|
Duration |
subtractTimestamp(Timestamp timestamp)
Returns a
Duration calculated as: this - timestamp . |
public static Timestamp create(long seconds, int nanos)
seconds
- Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be
from from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.nanos
- Non-negative fractions of a second at nanosecond resolution. Negative second
values with fractions must still have non-negative nanos values that count forward in time.
Must be from 0 to 999,999,999 inclusive.Timestamp
with specified fields.IllegalArgumentException
- if the arguments are out of range.public static Timestamp fromMillis(long epochMilli)
epochMilli
- the timestamp represented in milliseconds since epoch.Timestamp
with specified fields.IllegalArgumentException
- if the number of milliseconds is out of the range that can be
represented by Timestamp
.public abstract long getSeconds()
public abstract int getNanos()
public Timestamp addNanos(long nanosToAdd)
Timestamp
calculated as this Timestamp
plus some number of
nanoseconds.nanosToAdd
- the nanos to add, positive or negative.Timestamp
. For invalid inputs, a Timestamp
of zero is
returned.ArithmeticException
- if numeric overflow occurs.public Timestamp addDuration(Duration duration)
Timestamp
calculated as this Timestamp
plus some Duration
.duration
- the Duration
to add.Timestamp
with the specified Duration
added.public Duration subtractTimestamp(Timestamp timestamp)
Duration
calculated as: this - timestamp
.timestamp
- the Timestamp
to subtract.Duration
. For invalid inputs, a Duration
of zero is
returned.public int compareTo(Timestamp otherTimestamp)
Timestamp
to the specified Timestamp
.compareTo
in interface Comparable<Timestamp>
otherTimestamp
- the other Timestamp
to compare to, not null
.NullPointerException
- if otherTimestamp is null
.