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 FormModifier 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()
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()
Converts NTP timestamp to Java Date object.
|
long |
getFraction()
Returns low-order 32-bits representing the fractional seconds.
|
static TimeStamp |
getNtpTime(long dateMillis)
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()
Converts NTP timestamp to Java standard time.
|
static long |
getTime(long ntpTimeValue)
Converts 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 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 hex timestampNumberFormatException
- - if the string does not contain a parsable timestamp.protected static long decodeNtpHexString(String hexString) throws NumberFormatException
hexString
- the string to convertNumberFormatException
- - if the string does not contain a parsable timestamp.public static TimeStamp getCurrentTime()
System.currentTimeMillis()
public static TimeStamp getNtpTime(long dateMillis)
dateMillis
- the milliseconds since January 1, 1970, 00:00:00 GMT.public static long getTime(long ntpTimeValue)
ntpTimeValue
- the input timepublic static TimeStamp parseNtpString(String s) throws NumberFormatException
s
- - hexstring.NumberFormatException
- - if the string does not contain a parsable timestamp.protected static long toNtpTime(long millis)
millis
- Java timepublic 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.986ntpTime
- the 64 bit timestamppublic 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).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 Date getDate()
public long getFraction()
public long getSeconds()
public long getTime()
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))
public long ntpValue()
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 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.986public 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
Copyright © 2001–2022 The Apache Software Foundation. All rights reserved.