org.apache.commons.net.ntp
public class TimeStamp extends Object implements Serializable, Comparable
Methods exist to convert NTP timestamps to and from the equivalent Java date representation, which is the number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
Version: $Revision: 165675 $ $Date: 2005-05-02 15:09:55 -0500 (Mon, 02 May 2005) $
See Also: java.util.Date
Field Summary | |
---|---|
protected static long | msb0baseTime
baseline NTP time if bit-0=0 -> 7-Feb-2036 @ 06:28:16 UTC |
protected static long | msb1baseTime
baseline NTP time if bit-0=1 -> 1-Jan-1900 @ 01:00:00 UTC |
static String | NTP_DATE_FORMAT
Default NTP date string format. |
Constructor Summary | |
---|---|
TimeStamp(long ntpTime)
Constructs a newly allocated NTP timestamp object
that represents the native 64-bit long argument. | |
TimeStamp(String s)
Constructs a newly allocated NTP timestamp object
that represents the value represented by the string
in hexdecimal form (e.g. | |
TimeStamp(Date d)
Constructs a newly allocated NTP timestamp object
that represents the Java Date argument.
|
Method Summary | |
---|---|
int | compareTo(TimeStamp anotherTimeStamp)
Compares two Timestamps numerically.
|
int | compareTo(Object o)
Compares this TimeStamp to another Object. |
protected static long | decodeNtpHexString(String s)
Convert NTP timestamp hexstring (e.g. |
boolean | equals(Object obj)
Compares this object against the specified object.
|
static TimeStamp | getCurrentTime()
Constructs a NTP timestamp object and initializes it so that
it represents the time at which it was allocated, measured to the
nearest millisecond. |
Date | getDate()
Convert NTP timestamp to Java Date object.
|
long | getFraction()
Returns low-order 32-bits representing the fractional seconds.
|
static TimeStamp | getNtpTime(long date)
Helper method to convert Java time to NTP timestamp object.
|
long | getSeconds()
Returns high-order 32-bits representing the seconds of this NTP timestamp.
|
long | getTime()
Convert NTP timestamp to Java standard time.
|
static long | getTime(long ntpTimeValue)
Convert 64-bit NTP timestamp to Java standard time.
|
int | hashCode()
Computes a hashcode for this Timestamp. |
long | ntpValue()
Returns the value of this Timestamp as a long value.
|
static TimeStamp | parseNtpString(String s)
Parses the string argument as a NTP hexidecimal timestamp representation string
(e.g. |
String | toDateString()
Converts this TimeStamp object to a String
of the form:
See java.text.SimpleDataFormat for code descriptions.EEE, MMM dd yyyy HH:mm:ss.SSS |
protected static long | toNtpTime(long t)
Converts Java time to 64-bit NTP time representation.
|
String | toString()
Converts this TimeStamp object to a String .
|
static String | toString(long ntpTime)
Converts 64-bit NTP timestamp value to a String .
|
String | toUTCString()
Converts this TimeStamp object to a String
of the form:
See java.text.SimpleDataFormat for code descriptions.EEE, MMM dd yyyy HH:mm:ss.SSS UTC |
java.text.SimpleDateFormat
for code descriptions.Throws: NumberFormatException - if the string does not contain a parsable timestamp.
Parameters: d - the Date to be represented by the Timestamp object.
Parameters: anotherTimeStamp - the TimeStamp
to be compared.
Returns: the value 0
if the argument TimeStamp is equal to
this TimeStamp; a value less than 0
if this TimeStamp
is numerically less than the TimeStamp argument; and a
value greater than 0
if this TimeStamp is
numerically greater than the TimeStamp argument
(signed comparison).
compareTo(TimeStamp)
. Otherwise,
it throws a ClassCastException
(as TimeStamps are comparable
only to other TimeStamps).
Parameters: o the Object
to be compared.
Returns: the value 0
if the argument is a TimeStamp
numerically equal to this TimeStamp; a value less than
0
if the argument is a TimeStamp numerically
greater than this TimeStamp; and a value greater than
0
if the argument is a TimeStamp numerically
less than this TimeStamp.
Throws: ClassCastException if the argument is not a
TimeStamp
.
See Also: java.lang.Comparable
Returns: NTP 64-bit timestamp value.
Throws: NumberFormatException - if the string does not contain a parsable timestamp.
true
if and only if the argument is
not null
and is a Long
object that
contains the same long
value as this object.
Parameters: obj the object to compare with.
Returns: true
if the objects are the same;
false
otherwise.
Returns: NTP timestamp object set to the current time.
See Also: java.lang.System#currentTimeMillis()
Returns: NTP Timestamp in Java Date
Returns: fractional seconds represented by this NTP timestamp.
Parameters: date the milliseconds since January 1, 1970, 00:00:00 GMT.
Returns: NTP timestamp object at the specified date.
Returns: seconds represented by this NTP timestamp.
Returns: NTP Timestamp in Java time
Parameters: ntpTimeValue
Returns: the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this NTP timestamp value.
long
value
represented by this TimeStamp
object. That is, the hashcode
is the value of the expression:
(int)(this.ntpValue()^(this.ntpValue() >>> 32))
Returns: a hash code value for this object.
Returns: the 64-bit long value represented by this object.
Parameters: s - hexstring.
Returns: the Timestamp represented by the argument in hexidecimal.
Throws: NumberFormatException - if the string does not contain a parsable timestamp.
TimeStamp
object to a String
of the form:
See java.text.SimpleDataFormat for code descriptions.EEE, MMM dd yyyy HH:mm:ss.SSS
Returns: a string representation of this date.
Parameters: t Java time
Returns: NTP timestamp representation of Java time value.
TimeStamp
object to a String
.
The NTP timestamp 64-bit long value is represented as hex string with
seconds separated by fractional seconds by a decimal point;
e.g. c1a089bd.fc904f6d <=> Tue, Dec 10 2002 10:41:49.986
Returns: NTP timestamp 64-bit long value as hex string with seconds separated by fractional seconds.
String
.
The NTP timestamp value is represented as hex string with
seconds separated by fractional seconds by a decimal point;
e.g. c1a089bd.fc904f6d <=> Tue, Dec 10 2002 10:41:49.986
Returns: NTP timestamp 64-bit long value as hex string with seconds separated by fractional seconds.
TimeStamp
object to a String
of the form:
See java.text.SimpleDataFormat for code descriptions.EEE, MMM dd yyyy HH:mm:ss.SSS UTC
Returns: a string representation of this date in UTC.