public class Timestamp extends Object implements Comparable<Timestamp>
Note that while TimeStamp are usually created according to system clocks which may take into account leap seconds, all the math operations on TimeStamps do not take leap seconds into account.
javax.time.Instant
.
When it will be released, the plan is to phase out
this class in the same way that Date
is going to be phased out.
As of 2012/05/07, there are still multiple proposal on the table on that will
work, but in all cases it requires having this class implement a single
method interface and make all clients use that single method interface.Modifier and Type | Method and Description |
---|---|
int |
compareTo(Timestamp other)
Defines the natural ordering for timestamp as forward in time.
|
TimeDuration |
durationBetween(Timestamp time)
Calculates the time between the reference and this timeStamp.
|
TimeDuration |
durationFrom(Timestamp reference)
Calculates the time passed from the reference to this timeStamp.
|
boolean |
equals(Object obj) |
int |
getNanoSec()
Nanoseconds within the given second.
|
long |
getSec()
Unix time; seconds from midnight 1/1/1970.
|
int |
hashCode() |
Timestamp |
minus(TimeDuration duration)
Subtracts the given duration to this timestamp and returns the result.
|
static Timestamp |
now()
Returns a new timestamp for the current instant.
|
static Timestamp |
of(Date date)
Converts a
Date to a timestamp. |
static Timestamp |
of(long epochSec,
int nanoSec)
Returns a new timestamp from Java/UNIX time.
|
Timestamp |
plus(TimeDuration duration)
Adds the given duration to this timestamp and returns the result.
|
Date |
toDate()
Converts the time stamp to a standard Date.
|
String |
toString() |
public long getSec()
public int getNanoSec()
public static Timestamp of(long epochSec, int nanoSec)
epochSec
- number of seconds in the Java/UNIX epoch.nanoSec
- nanoseconds past the given seconds (must be 0 < nanoSec < 999,999,999)public static Timestamp of(Date date)
Date
to a timestamp. Date is accurate to
milliseconds, so the last 6 digits are always going to be zeros.date
- the date to convertpublic static Timestamp now()
System.nanoTime()
, so it has the accuracy given
by that function.public Date toDate()
public int compareTo(Timestamp other)
compareTo
in interface Comparable<Timestamp>
other
- another objectpublic Timestamp plus(TimeDuration duration)
duration
- a time durationpublic Timestamp minus(TimeDuration duration)
duration
- a time durationpublic TimeDuration durationBetween(Timestamp time)
time
- another time stamppublic TimeDuration durationFrom(Timestamp reference)
reference
- another time stampCopyright © 2015. All rights reserved.