|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.net.ntp.TimeStamp
public class TimeStamp
TimeStamp class represents the Network Time Protocol (NTP) timestamp as defined in RFC-1305 and SNTP (RFC-2030). It is represented as a 64-bit unsigned fixed-point number in seconds relative to 0-hour on 1-January-1900. The 32-bit low-order bits are the fractional seconds whose precision is about 200 picoseconds. Assumes overflow date when date passes MAX_LONG and reverts back to 0 is 2036 and not 1900. Test for most significant bit: if MSB=0 then 2036 basis is used otherwise 1900 if MSB=1.
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.
Date
,
Serialized FormField 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(Date d)
Constructs a newly allocated NTP timestamp object that represents the Java Date argument. |
|
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. |
Method Summary | |
---|---|
int |
compareTo(Object o)
Compares this TimeStamp to another Object. |
int |
compareTo(TimeStamp anotherTimeStamp)
Compares two Timestamps numerically. |
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:
|
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:
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final long msb0baseTime
protected static final long msb1baseTime
public static final String NTP_DATE_FORMAT
java.text.SimpleDateFormat
for code descriptions.
Constructor Detail |
---|
public TimeStamp(long ntpTime)
public TimeStamp(String s) throws NumberFormatException
NumberFormatException
- - if the string does not contain a parsable timestamp.public TimeStamp(Date d)
d
- - the Date to be represented by the Timestamp object.Method Detail |
---|
public long ntpValue()
public long getSeconds()
public long getFraction()
public long getTime()
public Date getDate()
public static long getTime(long ntpTimeValue)
ntpTimeValue
-
public static TimeStamp getNtpTime(long date)
date
- the milliseconds since January 1, 1970, 00:00:00 GMT.
public static TimeStamp getCurrentTime()
System.currentTimeMillis()
protected static long decodeNtpHexString(String s) throws NumberFormatException
NumberFormatException
- - if the string does not contain a parsable timestamp.public static TimeStamp parseNtpString(String s) throws NumberFormatException
s
- - hexstring.
NumberFormatException
- - if the string does not contain a parsable timestamp.protected static long toNtpTime(long t)
t
- Java time
public int hashCode()
long
value
represented by this TimeStamp
object. That is, the hashcode
is the value of the expression:
(int)(this.ntpValue()^(this.ntpValue() >>> 32))
hashCode
in class Object
public boolean equals(Object obj)
true
if and only if the argument is
not null
and is a Long
object that
contains the same long
value as this object.
equals
in class Object
obj
- the object to compare with.
true
if the objects are the same;
false
otherwise.public String toString()
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
toString
in class Object
public static String toString(long ntpTime)
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
public String toDateString()
TimeStamp
object to a String
of the form:
See java.text.SimpleDataFormat for code descriptions.EEE, MMM dd yyyy HH:mm:ss.SSS
public String toUTCString()
TimeStamp
object to a String
of the form:
See java.text.SimpleDataFormat for code descriptions.EEE, MMM dd yyyy HH:mm:ss.SSS UTC
public int compareTo(TimeStamp anotherTimeStamp)
anotherTimeStamp
- - the TimeStamp
to be compared.
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).public int compareTo(Object o)
compareTo(TimeStamp)
. Otherwise,
it throws a ClassCastException
(as TimeStamps are comparable
only to other TimeStamps).
compareTo
in interface Comparable
o
- the Object
to be compared.
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.
ClassCastException
- if the argument is not a
TimeStamp
.Comparable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |