Class Timestamp
java.lang.Object
io.opencensus.common.Timestamp
- All Implemented Interfaces:
Comparable<Timestamp>
- Direct Known Subclasses:
AutoValue_Timestamp
A representation of an instant in time. The instant is the number of nanoseconds after the number
of seconds since the Unix Epoch.
Use Tracing.getClock().now() to get the current timestamp since epoch
(1970-01-01T00:00:00Z).
- Since:
- 0.5
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddDuration(Duration duration) Returns aTimestampcalculated as thisTimestampplus someDuration.addNanos(long nanosToAdd) Returns aTimestampcalculated as thisTimestampplus some number of nanoseconds.intCompares thisTimestampto the specifiedTimestamp.static Timestampcreate(long seconds, int nanos) Creates a new timestamp from given seconds and nanoseconds.private static longfloorDiv(long x, long y) private static longfloorMod(long x, long y) static TimestampfromMillis(long epochMilli) Creates a new timestamp from the given milliseconds.abstract intgetNanos()Returns the number of nanoseconds after the number of seconds since the Unix Epoch represented by this timestamp.abstract longReturns the number of seconds since the Unix Epoch represented by this timestamp.private static TimestampofEpochSecond(long epochSecond, long nanoAdjustment) private Timestampplus(long secondsToAdd, long nanosToAdd) subtractTimestamp(Timestamp timestamp) Returns aDurationcalculated as:this - timestamp.
-
Constructor Details
-
Timestamp
Timestamp()
-
-
Method Details
-
create
Creates a new timestamp from given seconds and nanoseconds.- Parameters:
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.- Returns:
- new
Timestampwith specified fields. - Throws:
IllegalArgumentException- if the arguments are out of range.- Since:
- 0.5
-
fromMillis
Creates a new timestamp from the given milliseconds.- Parameters:
epochMilli- the timestamp represented in milliseconds since epoch.- Returns:
- new
Timestampwith specified fields. - Throws:
IllegalArgumentException- if the number of milliseconds is out of the range that can be represented byTimestamp.- Since:
- 0.5
-
getSeconds
public abstract long getSeconds()Returns the number of seconds since the Unix Epoch represented by this timestamp.- Returns:
- the number of seconds since the Unix Epoch.
- Since:
- 0.5
-
getNanos
public abstract int getNanos()Returns the number of nanoseconds after the number of seconds since the Unix Epoch represented by this timestamp.- Returns:
- the number of nanoseconds after the number of seconds since the Unix Epoch.
- Since:
- 0.5
-
addNanos
Returns aTimestampcalculated as thisTimestampplus some number of nanoseconds.- Parameters:
nanosToAdd- the nanos to add, positive or negative.- Returns:
- the calculated
Timestamp. For invalid inputs, aTimestampof zero is returned. - Throws:
ArithmeticException- if numeric overflow occurs.- Since:
- 0.5
-
addDuration
-
subtractTimestamp
-
compareTo
Compares thisTimestampto the specifiedTimestamp.- Specified by:
compareToin interfaceComparable<Timestamp>- Parameters:
otherTimestamp- the otherTimestampto compare to, notnull.- Returns:
- the comparator value: zero if equal, negative if this timestamp happens before otherTimestamp, positive if after.
- Throws:
NullPointerException- if otherTimestamp isnull.
-
plus
-
ofEpochSecond
-
floorDiv
private static long floorDiv(long x, long y) -
floorMod
private static long floorMod(long x, long y)
-