public class TimeStamp extends Object implements Serializable, Comparable<TimeStamp>
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 Form| Modifier and Type | Field and Description |
|---|---|
protected static long |
msb0baseTime
Baseline NTP time if bit-0=0 is 7-Feb-2036 @ 06:28:16 UTC
|
protected static long |
msb1baseTime
Baseline NTP time if bit-0=1 is 1-Jan-1900 @ 01:00:00 UTC
|
static String |
NTP_DATE_FORMAT
Default NTP date string format.
|
| Constructor and Description |
|---|
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 hexStamp)
Constructs a newly allocated NTP timestamp object that represents the value represented by the string in hexdecimal form (e.g.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(TimeStamp anotherTimeStamp)
Compares two Timestamps numerically.
|
protected static long |
decodeNtpHexString(String hexString)
Convert NTP timestamp hexstring (e.g.
|
boolean |
equals(Object obj)
Compares this object against the specified object.
|
static TimeStamp |
getCurrentTime()
Gets an NTP timestamp object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.
|
Date |
getDate()
Gets a Date for an NTP timestamp.
|
long |
getFraction()
Gets the low-order 32-bits representing the fractional seconds.
|
static TimeStamp |
getNtpTime(long dateMillis)
Gets an NTP timestamp object from a Java time.
|
long |
getSeconds()
Gets the high-order 32-bits representing the seconds of this NTP timestamp.
|
long |
getTime()
Gets a Java standard time in milliseconds from the NTP timestamp.
|
static long |
getTime(long ntpTimeValue)
Gets a Java standard time from a 64-bit NTP timestamp.
|
int |
hashCode()
Computes a hash code 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 millis)
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: |
protected static final long msb0baseTime
protected static final long msb1baseTime
public static final String NTP_DATE_FORMAT
java.text.SimpleDateFormat for code descriptions.public TimeStamp(Date d)
d - the Date to be represented by the Timestamp object.public TimeStamp(long ntpTime)
ntpTime - the timestamppublic TimeStamp(String hexStamp) throws NumberFormatException
hexStamp - the hexadecimal timestampNumberFormatException - - if the string does not contain a parsable timestamp.public int compareTo(TimeStamp anotherTimeStamp)
compareTo in interface Comparable<TimeStamp>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).protected static long decodeNtpHexString(String hexString) throws NumberFormatException
hexString - the string to convertNumberFormatException - - if the string does not contain a parsable timestamp.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.public static TimeStamp getCurrentTime()
System.currentTimeMillis()public Date getDate()
public long getFraction()
public static TimeStamp getNtpTime(long dateMillis)
dateMillis - the milliseconds since January 1, 1970, 00:00:00 GMT.public long getSeconds()
public long getTime()
public static long getTime(long ntpTimeValue)
ntpTimeValue - the input timepublic int hashCode()
long value represented by this
TimeStamp object. That is, the hash code is the value of the expression: (int) (this.ntpValue() ^ (this.ntpValue() >>> 32))
public long ntpValue()
public static TimeStamp parseNtpString(String s) throws NumberFormatException
s - hexstring.NumberFormatException - - if the string does not contain a parsable timestamp.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
protected static long toNtpTime(long millis)
millis - Java timepublic String toString()
TimeStamp object to a String. The NTP timestamp 64-bit long value is represented as hexadecimal string with
seconds separated by fractional seconds by a decimal point; e.g. c1a089bd.fc904f6d == Tue, Dec 10 2002 10:41:49.986public static String toString(long ntpTime)
String. The NTP timestamp value is represented as hexadecimal string with seconds separated by
fractional seconds by a decimal point; e.g. c1a089bd.fc904f6d == Tue, Dec 10 2002 10:41:49.986ntpTime - the 64 bit timestamppublic 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